@everfur/sdk 1.5.0 → 1.5.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.
- package/dist/{bookingCopy.d-BuDv16WP.d.ts → bookingCopy.d-BL2-URcv.d.ts} +3 -2
- package/dist/{bookingCopy.d-rnBSqOSN.d.cts → bookingCopy.d-Dfew1pjY.d.cts} +3 -2
- package/dist/care/index.cjs +2 -2
- package/dist/care/index.js +2 -2
- package/dist/chat/index.cjs +235 -234
- package/dist/chat/index.js +311 -310
- package/dist/chat/lite/index.cjs +339 -338
- package/dist/chat/lite/index.js +314 -313
- package/dist/{chunk-4KFFE42Z.js → chunk-2T5CB5MW.js} +20 -20
- package/dist/{chunk-HHCGXQJR.js → chunk-ASE36WGP.js} +11 -11
- package/dist/{chunk-6IHY7HS7.js → chunk-CMDCBYUH.js} +1 -1
- package/dist/{chunk-BMYNDBUR.js → chunk-K7YHXFPQ.js} +1 -1
- package/dist/client/index.cjs +1 -1
- package/dist/client/index.d.cts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +1 -1
- package/dist/core/index.cjs +31 -31
- package/dist/core/index.js +31 -31
- package/dist/health-plan/index.cjs +266 -266
- package/dist/health-plan/index.js +443 -443
- package/dist/{inbox.d-DJ9xgU1Z.d.ts → inbox.d-B2JXK0uI.d.ts} +1 -1
- package/dist/{inbox.d-CPcMMz-Y.d.cts → inbox.d-CwA1ogzV.d.cts} +1 -1
- package/dist/index.cjs +257 -256
- package/dist/index.js +364 -363
- package/dist/{models.d-BULqCO2R.d.ts → models.d-NAWqF1wC.d.ts} +4 -1
- package/dist/{models.d-BKmOfoqV.d.cts → models.d-wJ_Ze4p5.d.cts} +4 -1
- package/dist/notifications/inbox/index.cjs +28 -28
- package/dist/notifications/inbox/index.d.cts +5 -5
- package/dist/notifications/inbox/index.d.ts +5 -5
- package/dist/notifications/inbox/index.js +53 -53
- package/dist/notifications/index.cjs +1 -1
- package/dist/notifications/index.d.cts +3 -3
- package/dist/notifications/index.d.ts +3 -3
- package/dist/notifications/index.js +1 -1
- package/dist/{parse.d-Cj3fURer.d.ts → parse.d-QjB2LJCd.d.ts} +19 -10
- package/dist/{parse.d-cH7ZmMeo.d.cts → parse.d-_Ttu2h5g.d.cts} +19 -10
- package/dist/records/depth/index.cjs +80 -80
- package/dist/records/depth/index.js +115 -115
- package/dist/records/index.cjs +653 -653
- package/dist/records/index.js +1074 -1074
- package/dist/{route.d-DSYEd2MR.d.ts → route.d-DtuKY5dM.d.ts} +1 -1
- package/dist/{route.d-DCzQh4ix.d.cts → route.d-Nt-r-7IO.d.cts} +1 -1
- package/dist/server/events/index.cjs +1 -1
- package/dist/server/events/index.js +1 -1
- package/dist/server/index.cjs +1 -1
- package/dist/server/index.js +1 -1
- package/dist/shop/index.cjs +188 -188
- package/dist/shop/index.js +386 -386
- package/dist/shop/orders-v2/index.cjs +72 -72
- package/dist/shop/orders-v2/index.js +126 -126
- package/dist/tabs/index.cjs +114 -111
- package/dist/tabs/index.d.cts +19 -6
- package/dist/tabs/index.d.ts +19 -6
- package/dist/tabs/index.js +191 -188
- package/dist/televet/booking/index.cjs +214 -212
- package/dist/televet/booking/index.d.cts +2 -2
- package/dist/televet/booking/index.d.ts +2 -2
- package/dist/televet/booking/index.js +344 -342
- package/dist/televet/call/index.cjs +53 -53
- package/dist/televet/call/index.js +67 -67
- package/dist/{useInboxUnread.d-CXiaR3BZ.d.ts → useInboxUnread.d-0DrQPn7J.d.ts} +1 -1
- package/dist/{useInboxUnread.d-DERpMelw.d.cts → useInboxUnread.d-CRcOTkmu.d.cts} +1 -1
- package/dist/web/health-plan/index.cjs +1 -1
- package/dist/web/health-plan/index.js +1 -1
- package/dist/web/inbox/index.cjs +1 -1
- package/dist/web/inbox/index.d.cts +6 -6
- package/dist/web/inbox/index.d.ts +6 -6
- package/dist/web/inbox/index.js +1 -1
- package/dist/web/index.cjs +184 -184
- package/dist/web/index.js +181 -181
- package/dist/web/notifications/index.cjs +1 -1
- package/dist/web/notifications/index.d.cts +2 -2
- package/dist/web/notifications/index.d.ts +2 -2
- package/dist/web/notifications/index.js +1 -1
- package/dist/web/records-sheet/index.cjs +1 -1
- package/dist/web/records-sheet/index.js +1 -1
- package/dist/web/shop/index.cjs +1 -1
- package/dist/web/shop/index.js +2 -2
- package/dist/web/televet/booking/index.cjs +7 -8
- package/dist/web/televet/booking/index.d.cts +2 -2
- package/dist/web/televet/booking/index.d.ts +2 -2
- package/dist/web/televet/booking/index.js +7 -8
- package/dist/web/televet/call/index.cjs +1 -1
- package/dist/web/televet/call/index.js +1 -1
- package/dist/web/ui/index.cjs +1 -1
- package/dist/web/ui/index.js +33 -33
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ import { A as AuthContext } from './identity.d-D4VtpqRr.js';
|
|
|
6
6
|
import { U as UserRef, P as PetRef, R as RecordsRequestId } from './ids.d-B2GAAifq.js';
|
|
7
7
|
import { a as ChatCheckinTarget } from './checkin.d-CokpahFL.js';
|
|
8
8
|
import { V as VetVisitIntent } from './visitIntent.d-CY7mrflo.js';
|
|
9
|
-
import { d as EverfurNotification, g as EverfurNotificationTarget } from './parse.d-
|
|
9
|
+
import { d as EverfurNotification, g as EverfurNotificationTarget } from './parse.d-QjB2LJCd.js';
|
|
10
10
|
|
|
11
11
|
/** The push providers the registration route accepts. `apns` is refused with `provider_unsupported` until APNs direct lands. */
|
|
12
12
|
type PushProvider = 'expo' | 'fcm' | 'apns';
|
|
@@ -6,7 +6,7 @@ import { A as AuthContext } from './identity.d-DDpXOtas.cjs';
|
|
|
6
6
|
import { U as UserRef, P as PetRef, R as RecordsRequestId } from './ids.d-B2GAAifq.cjs';
|
|
7
7
|
import { a as ChatCheckinTarget } from './checkin.d-BP3ZWBfX.cjs';
|
|
8
8
|
import { V as VetVisitIntent } from './visitIntent.d-CY7mrflo.cjs';
|
|
9
|
-
import { d as EverfurNotification, g as EverfurNotificationTarget } from './parse.d-
|
|
9
|
+
import { d as EverfurNotification, g as EverfurNotificationTarget } from './parse.d-_Ttu2h5g.cjs';
|
|
10
10
|
|
|
11
11
|
/** The push providers the registration route accepts. `apns` is refused with `provider_unsupported` until APNs direct lands. */
|
|
12
12
|
type PushProvider = 'expo' | 'fcm' | 'apns';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*! @everfur/sdk. Copyright (c) 2026 Strand Health Inc. dba Everfur. All rights reserved. Use is subject to the Everfur SDK License: https://docs.everfur.com/license */
|
|
2
2
|
"use strict";var e=require("crypto");function ok(e,t){/* @__PURE__ */
|
|
3
3
|
return Object.freeze({ok:true,value:e})}function err(e){/* @__PURE__ */
|
|
4
|
-
return Object.freeze({ok:false,error:e})}var t=class _EverfurConfigError extends Error{constructor(e,t){super(t),this.name="EverfurConfigError",this.kind=e,Object.setPrototypeOf(this,_EverfurConfigError.prototype)}};function r(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var n="Everfur-Signature",a=300,i="v1",o=4096,l=64,s=/^[0-9]+$/,d=class _EverfurWebhookVerificationError extends Error{constructor(e){super(`Everfur webhook verification failed: ${e}`),this.name="EverfurWebhookVerificationError",this.code=e,Object.setPrototypeOf(this,_EverfurWebhookVerificationError.prototype)}};function constructEvent(r,n,i,o={}){let s=p(r),v=c(i),h=o.toleranceSeconds??a;if(!Number.isInteger(h)||h<0)throw new t("invalid-argument","toleranceSeconds must be a non-negative integer");let m=_(n),y=o.nowSeconds??Math.floor(Date.now()/1e3);if(Math.abs(y-m.timestamp)>h)throw new d("timestamp_outside_tolerance");let b=false;for(let t of v){let r=Buffer.from(u(t,m.timestamp,s),"ascii");for(let t of m.signatures){if(t.length!==l)continue;let n=Buffer.from(t,"utf8");n.length===r.length&&e.timingSafeEqual(r,n)&&(b=true)}}if(!b)throw new d("no_matching_signature");return f(s)}function generateTestSignatureHeader(e){let r=p(e.payload),n=c(e.secrets),a=e.timestamp??Math.floor(Date.now()/1e3);if(!Number.isSafeInteger(a)||a<0)throw new t("invalid-argument","timestamp must be a non-negative integer (unix seconds)");return[`t=${a}`,...n.map(e=>`${i}=${u(e,a,r)}`)].join(",")}function u(t,r,n){return e.createHmac("sha256",Buffer.from(t,"utf8")).update(`${r}.`,"ascii").update(n).digest("hex")}function p(e){if(typeof e=="string")return Buffer.from(e,"utf8");if(e instanceof Uint8Array)return e;throw new t("invalid-argument","constructEvent needs the raw request body (a string or a Buffer), not parsed JSON: re-serialised JSON does not reproduce the signed bytes.")}function c(e){let r=typeof e=="string"?[e]:Array.isArray(e)?e:[];if(r.length===0||r.some(e=>typeof e!="string"||e.length===0))throw new t("invalid-argument","at least one non-empty webhook signing secret is required");return r}function _(e){if(typeof e!="string"||e.length===0||e.length>o)throw new d("malformed_header");let t=null,r=[];for(let n of e.split(",")){let e=n.trim(),a=e.indexOf("=");if(a<0)throw new d("malformed_header");let o=e.slice(0,a),l=e.slice(a+1);if(o==="t"){if(t!==null||!s.test(l))throw new d("malformed_header");let e=Number(l);if(!Number.isSafeInteger(e))throw new d("malformed_header");t=e}else o===i&&r.push(l)}if(t===null||r.length===0)throw new d("malformed_header");return{timestamp:t,signatures:r}}function f(e){let t;try{t=JSON.parse(Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("utf8"))}catch{throw new d("malformed_payload")}if(!r(t))throw new d("malformed_payload");let{id:n,object:a,type:i,api_version:o,created:l,livemode:s,data:u}=t;if(typeof n!="string"||n.length===0||a!=="event"||typeof i!="string"||i.length===0||typeof o!="string"||typeof l!="number"||typeof s!="boolean"||!r(u)||!r(u.object))throw new d("malformed_payload");return t}var v=/^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^/?#]*)/;var h="1.5.
|
|
4
|
+
return Object.freeze({ok:false,error:e})}var t=class _EverfurConfigError extends Error{constructor(e,t){super(t),this.name="EverfurConfigError",this.kind=e,Object.setPrototypeOf(this,_EverfurConfigError.prototype)}};function r(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var n="Everfur-Signature",a=300,i="v1",o=4096,l=64,s=/^[0-9]+$/,d=class _EverfurWebhookVerificationError extends Error{constructor(e){super(`Everfur webhook verification failed: ${e}`),this.name="EverfurWebhookVerificationError",this.code=e,Object.setPrototypeOf(this,_EverfurWebhookVerificationError.prototype)}};function constructEvent(r,n,i,o={}){let s=p(r),v=c(i),h=o.toleranceSeconds??a;if(!Number.isInteger(h)||h<0)throw new t("invalid-argument","toleranceSeconds must be a non-negative integer");let m=_(n),y=o.nowSeconds??Math.floor(Date.now()/1e3);if(Math.abs(y-m.timestamp)>h)throw new d("timestamp_outside_tolerance");let b=false;for(let t of v){let r=Buffer.from(u(t,m.timestamp,s),"ascii");for(let t of m.signatures){if(t.length!==l)continue;let n=Buffer.from(t,"utf8");n.length===r.length&&e.timingSafeEqual(r,n)&&(b=true)}}if(!b)throw new d("no_matching_signature");return f(s)}function generateTestSignatureHeader(e){let r=p(e.payload),n=c(e.secrets),a=e.timestamp??Math.floor(Date.now()/1e3);if(!Number.isSafeInteger(a)||a<0)throw new t("invalid-argument","timestamp must be a non-negative integer (unix seconds)");return[`t=${a}`,...n.map(e=>`${i}=${u(e,a,r)}`)].join(",")}function u(t,r,n){return e.createHmac("sha256",Buffer.from(t,"utf8")).update(`${r}.`,"ascii").update(n).digest("hex")}function p(e){if(typeof e=="string")return Buffer.from(e,"utf8");if(e instanceof Uint8Array)return e;throw new t("invalid-argument","constructEvent needs the raw request body (a string or a Buffer), not parsed JSON: re-serialised JSON does not reproduce the signed bytes.")}function c(e){let r=typeof e=="string"?[e]:Array.isArray(e)?e:[];if(r.length===0||r.some(e=>typeof e!="string"||e.length===0))throw new t("invalid-argument","at least one non-empty webhook signing secret is required");return r}function _(e){if(typeof e!="string"||e.length===0||e.length>o)throw new d("malformed_header");let t=null,r=[];for(let n of e.split(",")){let e=n.trim(),a=e.indexOf("=");if(a<0)throw new d("malformed_header");let o=e.slice(0,a),l=e.slice(a+1);if(o==="t"){if(t!==null||!s.test(l))throw new d("malformed_header");let e=Number(l);if(!Number.isSafeInteger(e))throw new d("malformed_header");t=e}else o===i&&r.push(l)}if(t===null||r.length===0)throw new d("malformed_header");return{timestamp:t,signatures:r}}function f(e){let t;try{t=JSON.parse(Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("utf8"))}catch{throw new d("malformed_payload")}if(!r(t))throw new d("malformed_payload");let{id:n,object:a,type:i,api_version:o,created:l,livemode:s,data:u}=t;if(typeof n!="string"||n.length===0||a!=="event"||typeof i!="string"||i.length===0||typeof o!="string"||typeof l!="number"||typeof s!="boolean"||!r(u)||!r(u.object))throw new d("malformed_payload");return t}var v=/^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^/?#]*)/;var h="1.5.2";var m="2026-09-19",y="EVERFUR_API_BASE_URL";function b(e,t){/* @__PURE__ */
|
|
5
5
|
return Object.freeze({ok:false,failure:/* @__PURE__ */Object.freeze({reason:e,message:t})})}function tryResolveApiBaseUrl(e){let t=e?.trim(),r=t&&t.length>0?t:R(y);return r?C(r):b("missing-api-base-url",`apiBaseUrl is required: pass config.apiBaseUrl or set ${y}. The SDK never ships a hardcoded host.`)}function resolveApiBaseUrl(e){let r=tryResolveApiBaseUrl(e);if(!r.ok)throw new t("invalid-argument",r.failure.message);return r.value}function w(e){return e.slice(e.lastIndexOf("@")+1).replace(/:\d+$/,"").toLowerCase()}function g(e){return e.length===0||e.includes("@")?false:e.startsWith("[")&&e.endsWith("]")?true:!e.includes(":")}function E(e,t){let r=e.indexOf("://");return r<0||e.slice(r+3).includes("@")?false:g(t)}function S(e,t){return`${e}://${t}`}function C(e){let t=e.trim(),r=v.exec(t);if(r===null||r[2]===void 0||r[2].length===0)return b("malformed-api-base-url","apiBaseUrl is not a valid absolute URL");let n=(r[1]??"").toLowerCase(),a=w(r[2]);if(a.length===0)return b("malformed-api-base-url","apiBaseUrl is not a valid absolute URL");let i=E(t,a)?`: ${S(n,a)}`:"";if(n!=="https"){if(!(n==="http"&&T(a)))return n==="http"?b("insecure-api-base-url",`apiBaseUrl must use https (cleartext http is only allowed for localhost)${i}`):b("unsupported-api-base-url-scheme",`apiBaseUrl must be http(s)${i}`)}let o=t.endsWith("/")?t.slice(0,-1):t;/* @__PURE__ */
|
|
6
6
|
return Object.freeze({ok:true,value:o})}function T(e){let t=e.toLowerCase();return t==="localhost"||t==="127.0.0.1"||t==="[::1]"||t==="::1"}function R(e){let t=globalThis.process?.env?.[e];return typeof t=="string"&&t.trim().length>0?t.trim():void 0}var k="server";function D(e){return{"X-Everfur-SDK-Version":h,"X-Everfur-SDK-Platform":k,"X-Everfur-Contract":e}}var N="DAILY_QUOTA_EXCEEDED",O=/* @__PURE__ */new Set(["THROTTLINGEXCEPTION","RATELIMITED","TOOMANYREQUESTS"]);function F(e,t){if(!O.has(e.toUpperCase().replace(/[^A-Z0-9]/g,"")))return e;let r=t,n=r?.daily_limit??r?.error?.daily_limit;return typeof n=="number"&&Number.isFinite(n)?N:e}var I=[{wireCode:"AccessDeniedException",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"AuthorizationException",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"ConflictException",envelope:"http_envelope",httpStatus:409,retryable:true},{wireCode:"DAILY_QUOTA_EXCEEDED",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"FILE_TOO_LARGE",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"IDEMPOTENCY_KEY_IN_FLIGHT",envelope:"http_envelope",httpStatus:409,retryable:true},{wireCode:"IDEMPOTENCY_KEY_REUSED_DIFFERENT_REQUEST",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"INVALID_CONTENT_TYPE",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"InternalFailureException",envelope:"http_envelope",httpStatus:500,retryable:true},{wireCode:"MethodNotAllowedException",envelope:"http_envelope",httpStatus:405,retryable:false},{wireCode:"NotImplementedException",envelope:"http_envelope",httpStatus:501,retryable:false},{wireCode:"PaymentRequiredException",envelope:"http_envelope",httpStatus:402,retryable:false},{wireCode:"ResourceNotFoundException",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"ServiceUnavailableException",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"TIER_UPGRADE_REQUIRED",envelope:"http_envelope",httpStatus:402,retryable:false},{wireCode:"ThrottlingException",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"ValidationException",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"accessDenied",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"access_denied",envelope:"oauth_error",httpStatus:302,retryable:false},{wireCode:"anchor_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"anchor_ref_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"anonTokenInvalid",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"attachment_unreadable",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"authExpired",envelope:"http_envelope",httpStatus:401,retryable:true},{wireCode:"authRejected",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"before_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"bundle_mismatch",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"bundle_not_uploaded",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"bundles_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"catalog_empty_refused",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"catalog_shrink_refused",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"consent_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"consent_required",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"consent_scope_wrong_route",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"device_cipher_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"email_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"endpoint_not_allowed",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"environment_mismatch",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"event_cursor_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_filter_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_id_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"event_payload_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_type_not_available",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_type_unknown",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"idempotency_key_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"idempotency_key_required",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"idempotency_key_reused",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"inbox_cursor_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"insufficientCapability",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"insufficient_scope",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"internal_error",envelope:"sse_frame",httpStatus:200,retryable:false},{wireCode:"invalidRequest",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"invalid_client",envelope:"oauth_error",httpStatus:401,retryable:false},{wireCode:"invalid_client_metadata",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_grant",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_redirect_uri",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_request",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_scope",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_target",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"item_id_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"linked_account_read_only",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"mcp_connection_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"mcp_request_conflict",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"mcp_request_gone",envelope:"http_envelope",httpStatus:410,retryable:false},{wireCode:"mcp_request_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"not_found",envelope:"sse_frame",httpStatus:200,retryable:false},{wireCode:"not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"open_url_not_allowed",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"partner_visit_link_conflict",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"partner_visit_owner_only",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"partner_visit_pet_already_mapped",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"payload_too_large",envelope:"http_envelope",httpStatus:413,retryable:false},{wireCode:"petRefInUse",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"pet_health_list_removals_unconfirmed",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"pet_health_species_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"pet_not_registered",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"provider_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"rateLimited",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"read_target_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"record_species_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"record_subject_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"record_upload_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"records_consent_required",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"restricted_key",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"sandbox_only",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"session_required",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"session_revoked",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"share_limit_reached",envelope:"http_envelope",httpStatus:429,retryable:false},{wireCode:"slow_down",envelope:"oauth_error",httpStatus:429,retryable:true},{wireCode:"species_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"subscription_keys_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"tenant_filter_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"tenant_has_no_capabilities",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"tenant_resource_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"tenant_surface_not_enabled",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"ticket_not_resolved",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"tickets_disabled",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"timeout",envelope:"sse_frame",httpStatus:200,retryable:true},{wireCode:"timezone_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"token_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"unavailable",envelope:"sse_frame",httpStatus:200,retryable:true},{wireCode:"unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"unrestrictedKeyRequired",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"unsupported_grant_type",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"unsupported_response_type",envelope:"oauth_error",httpStatus:302,retryable:false},{wireCode:"user_ref_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"verify_mint_rate_limited",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"verify_mint_refused",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"verify_mint_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"verify_user_ref_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"web_push_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"webhook_endpoint_update_empty",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"webhook_endpoint_update_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"webhook_url_rejected",envelope:"http_envelope",httpStatus:400,retryable:false}],A=/* @__PURE__ */Object.freeze(I.map(e=>/* @__PURE__ */Object.freeze(e)));/* @__PURE__ */Object.freeze(A.map(e=>e.wireCode));var j=/* @__PURE__ */Object.freeze({ValidationException:"validationFailed",AuthorizationException:"authRejected",PaymentRequiredException:"paymentRequired",AccessDeniedException:"accessDenied",ResourceNotFoundException:"resourceNotFound",ConflictException:"conflict",ThrottlingException:"rateLimited",InternalFailureException:"internalError",NotImplementedException:"notImplemented",ServiceUnavailableException:"serviceUnavailable",MethodNotAllowedException:"validationFailed",authExpired:"authExpired",unavailable:"serviceUnavailable",session_required:"sessionRequired",session_revoked:"authExpired",anonTokenInvalid:"authRejected",accessDenied:"accessDenied",invalidRequest:"sdkUpdateRequired",authRejected:"authRejected",rateLimited:"rateLimited",insufficientCapability:"accessDenied",unrestrictedKeyRequired:"accessDenied",user_ref_invalid:"validationFailed",event_cursor_invalid:"validationFailed",event_filter_invalid:"validationFailed",event_payload_invalid:"validationFailed",event_type_unknown:"validationFailed",idempotency_key_invalid:"validationFailed",idempotency_key_required:"validationFailed",idempotency_key_reused:"idempotencyConflict",payload_too_large:"validationFailed",webhook_url_rejected:"validationFailed",webhook_endpoint_update_empty:"validationFailed",webhook_endpoint_update_invalid:"validationFailed",event_type_not_available:"conflict",record_subject_not_found:"resourceNotFound",records_consent_required:"conflict",record_species_unsupported:"validationFailed",record_upload_invalid:"validationFailed",FILE_TOO_LARGE:"validationFailed",INVALID_CONTENT_TYPE:"validationFailed",attachment_unreadable:"validationFailed",provider_unsupported:"validationFailed",token_invalid:"validationFailed",device_cipher_unavailable:"serviceUnavailable",email_invalid:"validationFailed",consent_required:"validationFailed",consent_invalid:"validationFailed",consent_scope_wrong_route:"validationFailed",IDEMPOTENCY_KEY_IN_FLIGHT:"idempotencyInFlight",IDEMPOTENCY_KEY_REUSED_DIFFERENT_REQUEST:"idempotencyConflict",DAILY_QUOTA_EXCEEDED:"quotaExceeded",TIER_UPGRADE_REQUIRED:"paymentRequired",not_found:"conversationNotFound",timeout:"streamTimeout",internal_error:"internalError",invalid_request:"validationFailed",invalid_client:"authRejected",invalid_grant:"authRejected",unsupported_grant_type:"validationFailed",invalid_scope:"validationFailed",invalid_target:"validationFailed",invalid_redirect_uri:"validationFailed",invalid_client_metadata:"validationFailed",unsupported_response_type:"validationFailed",access_denied:"accessDenied",slow_down:"rateLimited",mcp_request_not_found:"resourceNotFound",mcp_request_gone:"resourceNotFound",mcp_connection_not_found:"resourceNotFound",mcp_request_conflict:"conflict",sandbox_only:"accessDenied",tenant_has_no_capabilities:"conflict",verify_mint_refused:"accessDenied",verify_mint_rate_limited:"rateLimited",verify_mint_unavailable:"serviceUnavailable",verify_user_ref_invalid:"validationFailed",insufficient_scope:"accessDenied",tenant_filter_invalid:"validationFailed",tenant_resource_not_found:"resourceNotFound",tenant_surface_not_enabled:"conflict",pet_health_species_unsupported:"validationFailed",pet_health_list_removals_unconfirmed:"validationFailed",petRefInUse:"conflict",share_limit_reached:"conflict",pet_not_registered:"resourceNotFound",species_unsupported:"validationFailed",partner_visit_owner_only:"accessDenied",partner_visit_link_conflict:"conflict",partner_visit_pet_already_mapped:"conflict",linked_account_read_only:"conflict",catalog_empty_refused:"conflict",catalog_shrink_refused:"conflict",endpoint_not_allowed:"validationFailed",event_id_invalid:"validationFailed",inbox_cursor_invalid:"validationFailed",item_id_invalid:"validationFailed",open_url_not_allowed:"validationFailed",read_target_invalid:"validationFailed",subscription_keys_invalid:"validationFailed",web_push_unavailable:"serviceUnavailable",anchor_not_found:"resourceNotFound",anchor_ref_invalid:"validationFailed",before_invalid:"validationFailed",bundle_mismatch:"validationFailed",bundle_not_uploaded:"validationFailed",bundles_unavailable:"serviceUnavailable",environment_mismatch:"validationFailed",restricted_key:"accessDenied",ticket_not_resolved:"conflict",tickets_disabled:"resourceNotFound",timezone_invalid:"validationFailed"}),x=/* @__PURE__ */Object.freeze(A.map(e=>/* @__PURE__ */Object.freeze({wireCode:e.wireCode,envelope:e.envelope,retryable:e.retryable,normalized:j[e.wireCode]}))),U=new Map(x.map(e=>[e.envelope+e.wireCode.toUpperCase(),e])),q=/* @__PURE__ */Object.freeze(["http_envelope",...[...new Set(x.map(e=>e.envelope))].filter(e=>e!=="http_envelope").sort()]);function contractErrorFor(e,t){if(typeof e!="string")return;let r=e.trim().toUpperCase();if(r.length!==0)for(let e of[t??"http_envelope",...q]){let t=U.get(e+r);if(t)return t}}var L=/* @__PURE__ */Object.freeze({authExpired:"authentication",authRejected:"authentication",sessionRequired:"authentication",identitySignatureRequired:"authentication",accessDenied:"authorization",paymentRequired:"entitlement",quotaExceeded:"rateLimit",rateLimited:"rateLimit",validationFailed:"invalidRequest",sdkUpdateRequired:"invalidRequest",runtimeDisposed:"invalidRequest",conversationNotFound:"notFound",petNotFound:"notFound",resourceNotFound:"notFound",conflict:"conflict",idempotencyConflict:"conflict",idempotencyInFlight:"conflict",streamTimeout:"connection",streamIncomplete:"connection",upstreamLlmTimeout:"connection",serviceUnavailable:"connection",internalError:"server",notImplemented:"server",mediaUploadFailed:"media",moderationBlocked:"policy",unknown:"unknown"});function categoryFor(e){return L[e]}function fromWire(e){let t=contractErrorFor(e);if(t)return t.normalized;let r=(e??"").trim().toUpperCase(),n=r.replace(/[^A-Z0-9]/g,"");if(n==="AUTHREJECTED")return"authRejected";if(r.startsWith("AUTH"))return"authExpired";switch(n){case"DAILYQUOTAEXCEEDED":case"QUOTAEXCEEDED":return"quotaExceeded";case"RATELIMITED":case"TOOMANYREQUESTS":case"TELEVETRATELIMITED":return"rateLimited";case"IDEMPOTENCYKEYCONFLICT":case"IDEMPOTENCYCONFLICT":return"idempotencyConflict";case"ACCESSDENIED":case"FORBIDDEN":return"accessDenied";case"IDENTITYSIGNATUREREQUIRED":return"identitySignatureRequired";case"FREECAPREACHED":return"paymentRequired";case"RUNTIMEDISPOSED":return"runtimeDisposed";case"NOTFOUND":case"CONVERSATIONNOTFOUND":return"conversationNotFound";case"PETNOTFOUND":return"petNotFound";case"TIMEOUT":case"STREAMTIMEOUT":return"streamTimeout";case"MEDIAUPLOADFAILED":case"UNRECOGNIZEDVIDEOFORMAT":case"FILETOOSMALL":return"mediaUploadFailed";case"MODERATIONBLOCKED":return"moderationBlocked";case"UPSTREAMLLMTIMEOUT":return"upstreamLlmTimeout";case"INTERNALERROR":case"INTERNALSERVERERROR":return"internalError";case"STREAMINCOMPLETE":case"CHATSTREAMINCOMPLETE":return"streamIncomplete";case"INVALIDANALYSISTYPE":case"INVALIDUPLOADPURPOSE":return"unknown";default:return"unknown"}}function fromHttpStatus(e){return e===401?"authExpired":e===403?"accessDenied":e===404?"conversationNotFound":e===409?"idempotencyConflict":e===421?"unknown":e===429?"rateLimited":e===400||e===422?"unknown":e>=500?"internalError":"unknown"}var $=/* @__PURE__ */new Set(["streamTimeout","rateLimited","internalError","upstreamLlmTimeout","streamIncomplete"]);function isAutoRetryable(e){return $.has(e)}var P=/* @__PURE__ */new Set(["serviceUnavailable","conflict","idempotencyInFlight"]);function isRetryableCode(e){return isAutoRetryable(e)||P.has(e)}var M="This feature isn't available on your account right now.",z="Something in that request was not right. Check the details and try again.",V=/* @__PURE__ */Object.freeze({authExpired:"Please sign in again to continue.",authRejected:"Please sign in again to continue.",sessionRequired:"This app needs to be updated to keep using Everfur.",accessDenied:M,paymentRequired:"This is part of a paid plan.",quotaExceeded:"You have used today's messages. This resets tomorrow.",rateLimited:"You are sending messages quickly. Try again in a few seconds.",validationFailed:z,sdkUpdateRequired:"This app needs to be updated to keep using Everfur.",conflict:"That is already running. Wait for it to finish, then try again.",idempotencyConflict:"That message was already delivered.",idempotencyInFlight:"That is still processing. Give it a moment.",conversationNotFound:"This conversation is no longer available.",petNotFound:"We could not find that pet. Please pick a pet and try again.",resourceNotFound:"We could not find that.",streamTimeout:"The response timed out. Tap retry to try again.",mediaUploadFailed:"We could not upload that photo. Please attach it again.",moderationBlocked:"This request cannot be answered here.",upstreamLlmTimeout:"The response timed out. Tap retry to try again.",internalError:"We hit a snag on our end. Please try again.",notImplemented:"That is not available yet.",serviceUnavailable:"That service is briefly unavailable. Try again shortly.",streamIncomplete:"The connection dropped mid-answer. Tap retry to continue.",identitySignatureRequired:M,runtimeDisposed:z,unknown:"Something went wrong. Please try again."}),Y="This session has ended. Please sign in again.",B="linked_account_read_only";function K(e,t,r){return e==="conflict"&&r===B?M:(e==="authRejected"||e==="authExpired")&&typeof t=="string"&&t.trim().toLowerCase()==="session_revoked"?Y:userFacingError(e)}function userFacingError(e){return V[e]}function W(e,t,r){Object.defineProperty(e,t,{value:r,enumerable:false,writable:false,configurable:false})}var H=/^[a-z][a-z0-9_]{0,63}$/;function makeEverfurError(e,t){let r=contractErrorFor(t?.wireCode,t?.wireEnvelope),n=e==="conflict"&&t?.reasonCode===B,a={code:e,category:categoryFor(e),retryable:t?.retryable??(n?false:isRetryableCode(e)),displayMessage:K(e,t?.wireCode,n?B:null)};t?.httpStatus!==void 0&&(a.httpStatus=t.httpStatus),t?.requestId&&(a.requestId=t.requestId),typeof t?.reasonCode=="string"&&H.test(t.reasonCode)&&(a.reasonCode=t.reasonCode);let i=t?.retryAfterSeconds;if(typeof i=="number"&&Number.isFinite(i)&&i>=0&&(a.retryAfterSeconds=Math.round(i)),r);return t?.wireMessage&&W(a,"wireMessage",t.wireMessage),t?.raw!==void 0&&t.raw!==null&&W(a,"raw",t.raw),/* @__PURE__ */Object.freeze(a)}var G="free_cap_reached";function Q(e){return typeof e=="number"&&Number.isInteger(e)&&e>=0?e:null}function Z(e){if(typeof e!="object"||e===null)return null;let t=e,r=t.detail,n=typeof r=="object"&&r!==null?r:t;if(n.error!==G&&n.code!==G)return null;let a=Q(n.limit),i=Q(n.used);if(a===null||i===null)return null;let o=n.resets_at,l=n.emergency_guidance;/* @__PURE__ */
|
|
7
7
|
return Object.freeze({limit:a,used:i,resetsAt:typeof o=="string"&&o.length>0?o:null,...typeof l=="string"&&l.trim().length>0?{emergencyGuidance:l}:{}})}function X(e,t){if(e.status!==429&&e.status!==503)return t;let r=ee(e.headers.get(J),Date.now());if(r===null)return t;let n=t!==null&&typeof t=="object"&&!Array.isArray(t)?t:null;return n!==null&&te(n)?t:{...n??{},retry_after_seconds:r}}var J="retry-after";function ee(e,t){if(e===null)return null;let r=e.trim();if(/^\d+$/.test(r))return Number(r);let n=Date.parse(r);return Number.isFinite(n)?Math.max(0,Math.ceil((n-t)/1e3)):null}function te(e){return[e,e.error,e.detail].some(e=>e!==null&&typeof e=="object"&&("retry_after_seconds"in e||"resets_at"in e))}var re="x-request-id";function errorFromResponse(e,t,r){let n=ie(t),a=n?fromWire(n):fromHttpStatus(e),i=oe(t);return makeEverfurError(a,{httpStatus:e,...le(t)?{retryable:true}:{},...r?{requestId:r}:{},...n?{wireCode:n}:{},...ae(t)?{reasonCode:ae(t)}:{},...ne(t)!==null?{retryAfterSeconds:ne(t)}:{},...i?{wireMessage:i}:{},...t!=null?{raw:t}:{}})}function ne(e){let t=e,r=t?.retry_after_seconds??t?.error?.retry_after_seconds;return typeof r=="number"&&Number.isFinite(r)&&r>=0?r:null}function networkError(e){return makeEverfurError("internalError",{retryable:true,wireMessage:se(e)})}function requestIdOf(e){let t=e.headers.get(re);return typeof t=="string"&&t.length>0?t:null}function getGlobalFetch(){let e=globalThis.fetch;if(typeof e!="function")throw new t("missing-peer-dependency","global fetch is unavailable; provide config.transport or an injected fetch implementation");return e}function ae(e){let t=e,r=t?.error?.reason_code??t?.reason_code;return typeof r=="string"&&r.length>0?r:null}function ie(e){let t=e,r=t?.error?.code??t?.code;return typeof r=="string"&&r.length>0?F(r,e):Z(e)!==null?G:null}function oe(e){let t=e,r=t?.error?.message??t?.message;return typeof r=="string"&&r.length>0?r:null}function le(e){let t=e;return t?.error?.retryable===true||t?.retryable===true}function se(e){return e instanceof Error?e.message:typeof e=="string"?e:"network request failed"}var de=/* @__PURE__ */Object.freeze(["member.linked","member.unlinked","visit.booked","visit.cancelled","visit.completed","visit.no_show","record_request.updated","record.ready","webhook_endpoint.test","chat.follow_up_due","chat.urgency.flagged","pet.vaccination.due","visit.rescheduled","visit.reminder","visit.followup_sent","chat.reminder_due","record.activation","visit.message_received","visit.ended","contact.exported","health_plan.box_due","health_plan.one_box_ordered","claim.evidence_returned","claim.evidence_updated","claim.records_requested","claim.failed","claim.duplicate","claim.decided","claim.inbound_refused","insured_pet.profile.ready","insured_pet.profile.updated","chat.engagement_message","visit.notes_ready","visit.vet_joined","visit.summary_sent","chat.answer_ready","chat.follow_up_day5_due","care.medication_check_due","care.dose_due","care.refill_due","care.prevention_due","care.meal_due","care.nose_to_tail_due","care.reminder_due","record.labs_ready","record.update_available","order.updated","order.prescription_updated","walk.reminder","walk.reminder_offer","weather.heat","weather.storm","weather.air_quality","weather.ice","weather.pollen","safety.danger_day","safety.food_recall","insight.week","insight.birthday","tip.weekly","tip.daily","insight.weight_trend","tip.question_guide","insight.monthly_notes","pet.adoption_day","insight.year_summary","pack.walk_logged","pack.question","pack.reactions","pack.care_handoff","pack.photo_ready","mood.check_in_due","streak.at_risk","streak.milestone","membership.first_visit","membership.renewal","membership.invite","support.replied"]),ue=/* @__PURE__ */Object.freeze(["member.linked","member.unlinked","chat.urgency.flagged","webhook_endpoint.test","contact.exported","health_plan.box_due","health_plan.one_box_ordered","claim.evidence_returned","claim.evidence_updated","claim.records_requested","claim.failed","claim.duplicate","claim.decided","claim.inbound_refused","insured_pet.profile.ready","insured_pet.profile.updated"]);function isEverfurWebhookEventType(e){return typeof e=="string"&&de.includes(e)}function isEverfurWebhookEvent(e){return isEverfurWebhookEventType(e.type)}var pe=/* @__PURE__ */Object.freeze(["pet.profile.updated","pet.incident.reported","pet.behavior_note.added","pet.service_score.recorded","pet.deleted","member.status_changed","member.deleted"]);var ce=["sk_partner_","rk_partner_"];function _e(e,r){if(typeof e!="string"||e.length===0)throw new t("invalid-argument","partnerSecretKey is required");if(e.startsWith("pk_"))throw new t("invalid-argument",`partnerSecretKey is a publishable key (pk_...): ${r} needs your secret key, server side only`);if(!ce.some(t=>e.startsWith(t)))throw new t("invalid-argument","partnerSecretKey must be an sk_partner_ secret key or an rk_partner_ restricted key")}var fe=128;function assertValidUserRef(e){let r=typeof e=="string"?[...e].length:0;if(typeof e!="string"||r<1||r>fe)throw new t("invalid-argument",`user_ref must be 1..${fe} characters`);if(e.trim().length===0)throw new t("invalid-argument","user_ref must not be blank: the server strips surrounding whitespace before validating, so a whitespace-only value arrives empty and is rejected as required.");if(e!==e.trim())throw new t("invalid-argument","user_ref must not have leading or trailing whitespace: the server strips it, so padded and unpadded forms of the same id resolve to ONE user. Pass the exact id you want to key on.");if(e.includes("@"))throw new t("invalid-argument","user_ref must not contain '@'");if(!ve(e))throw new t("invalid-argument","user_ref must be printable (no control characters)");return e}function ve(e){return!he.test(e)}var he=/[\p{Cc}\p{Cf}\p{Cs}\p{Co}\p{Cn}\p{Zl}\p{Zp}]|(?!\u0020)[\p{Zs}]/u;function me(e){for(let t=0;t<e.length;t+=1){let r=e.charCodeAt(t);if(r>=55296&&r<=56319){let r=e.charCodeAt(t+1);if(!(r>=56320&&r<=57343))return true;t+=1}else if(r>=56320&&r<=57343)return true}return false}function ye(e){return[...e].length}var be=/* @__PURE__ */Object.freeze({dog:"dog",canine:"dog",k9:"dog",puppy:"dog",cat:"cat",feline:"cat",kitten:"cat"});function canonicalPetSpecies(e){if(typeof e!="string")return null;let t=e.trim().toLowerCase();return Object.prototype.hasOwnProperty.call(be,t)?be[t]:null}var we=50,ge=128,Ee=120,Se=120,Ce=2e3,Te=120,Re=80,ke=/* @__PURE__ */new Set(["male","female","unknown"]),De=/* @__PURE__ */new Set(["day","month","year"]),Ne=/* @__PURE__ */new Set(["low","medium","high","athletic"]),Oe=/* @__PURE__ */new Set(["indoor","outdoor","both"]),Fe=/* @__PURE__ */new Set(["mild","moderate","severe"]),Ie=/^(\d{4})-(\d{2})-(\d{2})$/,Ae=[["sex","sex"],["spayedNeutered","spayed_neutered"],["birthDate","birth_date"],["birthDatePrecision","birth_date_precision"],["activityLevel","activity_level"],["indoorOutdoor","indoor_outdoor"],["foodBrand","food_brand"],["foodType","food_type"],["microchipId","microchip_id"]],je=[["allergies","allergies"],["medications","medications"],["supplements","supplements"],["conditions","conditions"]];/* @__PURE__ */Object.freeze([...Ae,...je].map(([e])=>e));function xe(e){let t=Ie.exec(e);if(t===null)return false;let[r,n,a]=[Number(t[1]),Number(t[2]),Number(t[3])],i=new Date(Date.UTC(r,n-1,a));return i.getUTCFullYear()===r&&i.getUTCMonth()===n-1&&i.getUTCDate()===a}var Ue=e=>(t,r)=>typeof r=="string"&&e.has(r)?null:`${t} must be one of ${[...e].join(", ")}`,qe=(e,t)=>typeof t=="boolean"?null:`${e} must be true or false`,Le=(e,t)=>typeof t=="string"&&xe(t)?null:`${e} must be a real date written YYYY-MM-DD`,$e=(e,t={})=>(r,n)=>{if(typeof n!="string")return`${r} must be a string`;if(me(n))return`${r} contains an unpaired surrogate and cannot be encoded`;let a=t.trimmed?n.trim():n;if(t.required&&a.length===0)return`${r} is required and must not be blank`;let i=ye(a);return i<=e?null:`${r} is ${i} characters; the server accepts at most ${e}`},Pe={sex:Ue(ke),spayedNeutered:qe,birthDate:Le,birthDatePrecision:Ue(De),activityLevel:Ue(Ne),indoorOutdoor:Ue(Oe),foodBrand:$e(Te),foodType:$e(Te),microchipId:$e(Re)},Me=["ref","ref",false,$e(ge,{required:true,trimmed:true})],ze=["notes","notes",false,$e(Ce,{trimmed:true})],Ve=[Me,["name","name",true,$e(Ee,{required:true,trimmed:true})],["dose","dose",false,$e(Se,{trimmed:true})],["frequency","frequency",false,$e(Se,{trimmed:true})],["startDate","start_date",false,Le],["endDate","end_date",false,Le],ze],Ye={allergies:[Me,["allergen","allergen",true,$e(Ee,{required:true,trimmed:true})],["severity","severity",false,Ue(Fe)],ze],medications:Ve,supplements:Ve,conditions:[Me,["conditionName","condition_name",true,$e(Ee,{required:true,trimmed:true})],["diagnosedDate","diagnosed_date",false,Le],ze]};function Be(e,t,r){let n=`${e}[${t}]`;if(typeof r!="object"||r===null||Array.isArray(r))return{error:`${n} must be an object`};let a=r,i={};for(let[t,r,o,l]of Ye[e]){let e=a[t];if(e==null){if(o)return{error:`${n}.${t} is required`};e===null&&(i[r]=null);continue}let s=l(`${n}.${t}`,e);if(s!==null)return{error:s};i[r]=e}let o=i.start_date,l=i.end_date;return typeof o=="string"&&typeof l=="string"&&l<o?{error:`${n}.endDate must not be before startDate`}:{item:i}}function Ke(e,t){if(!Array.isArray(t))return{error:`${e} must be an array (send [] to clear it)`};if(t.length>we)return{error:`${e} has ${t.length} items; the server accepts at most ${we}`};let r=[],n=/* @__PURE__ */new Set;for(let a=0;a<t.length;a+=1){let i=Be(e,a,t[a]);if("error"in i)return i;let o=i.item.ref;if(typeof o=="string"){let t=o.trim();if(n.has(t))return{error:`${e}: ref ${JSON.stringify(t)} is used twice; a ref names one item`};n.add(t)}r.push(i.item)}return{items:r}}function We(e,t){let r=e,n={};for(let[e,t]of Ae){let a=r[e];if(a!==void 0){if(a!==null){let t=Pe[e](e,a);if(t!==null)return{error:t}}n[t]=a}}let a=r.birthDate!==void 0,i=r.birthDatePrecision!==void 0;if(a!==i||a&&r.birthDate===null!=(r.birthDatePrecision===null))return{error:"birthDate and birthDatePrecision must be sent together, both set or both null"};for(let[e,t]of je){let a=r[e];if(a===void 0)continue;let i=Ke(e,a);if("error"in i)return i;n[t]=i.items}return Object.keys(n).length>0&&t!==void 0&&canonicalPetSpecies(t)===null?{error:"health fields need a pet Everfur reads as a dog or a cat (dog, canine, k9, puppy, cat, feline, kitten)"}:{body:n}}var He=[["name","name"],["species","species"],["breed","breed"],["ageYears","age_years"],["weightKg","weight_kg"],["partnerLabelInstructions","partner_label_instructions"]];function Ge(e){if(typeof e!="object"||e===null||Array.isArray(e))throw new t("invalid-argument","the pet profile must be an object");let r={};for(let[t,n]of He)e[t]!==void 0&&(r[n]=e[t]);let n=We(e,e.species);if("error"in n)throw new t("invalid-argument",n.error);return Object.assign(r,n.body)}var Qe=/^[\x21-\x7e]{1,255}$/,Ze=32*1024,Xe=/^\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:[Zz]|[+-]\d{2}:?\d{2})$/,Je=3e4,et=/* @__PURE__ */Object.freeze({"pet.profile.updated":{subject:"pet",schemaVersions:[1,2]},"pet.incident.reported":{subject:"pet",schemaVersions:[1]},"pet.behavior_note.added":{subject:"pet",schemaVersions:[1]},"pet.service_score.recorded":{subject:"pet",schemaVersions:[1]},"pet.deleted":{subject:"pet",schemaVersions:[1]},"member.status_changed":{subject:"member",schemaVersions:[1]},"member.deleted":{subject:"member",schemaVersions:[1]}});async function sendPartnerEvent(r,n,a){let i=a??e.randomUUID();if(typeof i!="string"||!Qe.test(i))throw new t("invalid-argument","idempotencyKey must be 1 to 255 visible ASCII characters (no spaces, no control or non-ASCII characters)");_e(r.partnerSecretKey,"sending events");let o=it(rt(n)),l=r.fetchImpl??getGlobalFetch(),s=`${resolveApiBaseUrl(r.apiBaseUrl)}/partners/events`,d={...D(r.contractVersion??m),accept:"application/json","content-type":"application/json","idempotency-key":i,"x-everfur-partner-secret-key":r.partnerSecretKey},u=new AbortController,p=setTimeout(()=>u.abort(),Je),c;try{c=await l(s,{method:"POST",headers:d,body:o,signal:u.signal})}catch(e){return err(networkError(e))}finally{clearTimeout(p)}let _=null;try{_=await c.json()}catch{_=null}let f=requestIdOf(c);if(!c.ok)return err(errorFromResponse(c.status,X(c,_),f));let v=ot(_,i);return v?ok(v):err(errorFromResponse(502,{error:{code:"INTERNAL_ERROR"}},f))}function tt(e){return typeof e=="string"&&pe.includes(e)}function rt(e){if(typeof e!="object"||e===null)throw new t("invalid-argument","event is required");if(!tt(e.type))throw new t("invalid-argument",`event.type must be one of ${pe.join(", ")}`);let r=et[e.type],n=e.schemaVersion??1;if(typeof n!="number"||!r.schemaVersions.includes(n))throw new t("invalid-argument",`event.schemaVersion must be one of ${r.schemaVersions.join(", ")} for ${e.type}`);let userRef=assertValidUserRef(e.userRef);if(r.subject==="pet"&&e.petRef===void 0)throw new t("invalid-argument",`event.petRef is required for ${e.type}`);if(r.subject==="member"&&e.petRef!==void 0)throw new t("invalid-argument",`event.petRef is not accepted on ${e.type}`);let petRef=e.petRef===void 0?void 0:nt(e.petRef);if(typeof e.data!="object"||e.data===null||Array.isArray(e.data))throw new t("invalid-argument","event.data must be an object");let a=e.type==="pet.profile.updated"&&n===2?Ge(e.data):e.data,i={type:e.type,schema_version:n,user_ref:userRef,occurred_at:at(e.occurredAt),data:a};return petRef!==void 0&&(i.pet_ref=petRef),i}function nt(e){try{return assertValidUserRef(e)}catch(e){throw e instanceof t?new t("invalid-argument",`event.petRef follows the user_ref rule: ${e.message}`):e}}function at(e){if(typeof e=="string"&&!Xe.test(e))throw new t("invalid-argument","event.occurredAt must be a Date or an ISO 8601 date-time with an explicit offset (Z or +05:30)");let r=e instanceof Date?e:typeof e=="string"?new Date(e):new Date(Number.NaN);if(Number.isNaN(r.getTime()))throw new t("invalid-argument","event.occurredAt must be a Date or an ISO 8601 date-time with an explicit offset (Z or +05:30)");return r.toISOString()}function it(e){let r;try{r=JSON.stringify(e)}catch{throw new t("invalid-argument","event.data must be JSON-serialisable")}let n=(new TextEncoder).encode(r).byteLength;if(n>Ze)throw new t("invalid-argument",`the event is ${n} bytes once serialised; Everfur accepts at most ${Ze} (32 KB)`);return r}function ot(e,t){if(typeof e!="object"||e===null)return null;let r=e,n=r.id,a=r.type,i=r.schema_version,userRef=r.user_ref,petRef=r.pet_ref??null,o=r.occurred_at,l=r.received_at,s=r.status,d=r.livemode;return typeof n!="string"||n.length===0||!tt(a)||typeof i!="number"||typeof userRef!="string"||petRef!==null&&typeof petRef!="string"||typeof o!="string"||typeof l!="string"||typeof s!="string"||typeof d!="boolean"?null:/* @__PURE__ */Object.freeze({id:n,type:a,schemaVersion:i,userRef:userRef,petRef:petRef,occurredAt:o,receivedAt:l,status:s,livemode:d,idempotencyKey:t})}exports.DEFAULT_WEBHOOK_TOLERANCE_SECONDS=a;exports.EVERFUR_SIGNATURE_HEADER=n;exports.EVERFUR_WEBHOOK_EVENT_TYPES=de;exports.EVERFUR_WEBHOOK_ONLY_EVENT_TYPES=ue;exports.EverfurWebhookVerificationError=d;exports.PARTNER_INBOUND_EVENT_TYPES=pe;exports.constructEvent=constructEvent;exports.generateTestSignatureHeader=generateTestSignatureHeader;exports.isEverfurWebhookEvent=isEverfurWebhookEvent;exports.isEverfurWebhookEventType=isEverfurWebhookEventType;exports.sendPartnerEvent=sendPartnerEvent;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*! @everfur/sdk. Copyright (c) 2026 Strand Health Inc. dba Everfur. All rights reserved. Use is subject to the Everfur SDK License: https://docs.everfur.com/license */
|
|
2
2
|
import{timingSafeEqual as e,createHmac as t,randomUUID as r}from"crypto";function ok(e,t){/* @__PURE__ */
|
|
3
3
|
return Object.freeze({ok:true,value:e})}function err(e){/* @__PURE__ */
|
|
4
|
-
return Object.freeze({ok:false,error:e})}var n=class _EverfurConfigError extends Error{constructor(e,t){super(t),this.name="EverfurConfigError",this.kind=e,Object.setPrototypeOf(this,_EverfurConfigError.prototype)}};function a(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var i="Everfur-Signature",o=300,l="v1",s=4096,d=64,u=/^[0-9]+$/,p=class _EverfurWebhookVerificationError extends Error{constructor(e){super(`Everfur webhook verification failed: ${e}`),this.name="EverfurWebhookVerificationError",this.code=e,Object.setPrototypeOf(this,_EverfurWebhookVerificationError.prototype)}};function constructEvent(t,r,a,i={}){let l=f(t),s=_(a),u=i.toleranceSeconds??o;if(!Number.isInteger(u)||u<0)throw new n("invalid-argument","toleranceSeconds must be a non-negative integer");let m=v(r),y=i.nowSeconds??Math.floor(Date.now()/1e3);if(Math.abs(y-m.timestamp)>u)throw new p("timestamp_outside_tolerance");let b=false;for(let t of s){let r=Buffer.from(c(t,m.timestamp,l),"ascii");for(let t of m.signatures){if(t.length!==d)continue;let n=Buffer.from(t,"utf8");n.length===r.length&&e(r,n)&&(b=true)}}if(!b)throw new p("no_matching_signature");return h(l)}function generateTestSignatureHeader(e){let t=f(e.payload),r=_(e.secrets),a=e.timestamp??Math.floor(Date.now()/1e3);if(!Number.isSafeInteger(a)||a<0)throw new n("invalid-argument","timestamp must be a non-negative integer (unix seconds)");return[`t=${a}`,...r.map(e=>`${l}=${c(e,a,t)}`)].join(",")}function c(e,r,n){return t("sha256",Buffer.from(e,"utf8")).update(`${r}.`,"ascii").update(n).digest("hex")}function f(e){if(typeof e=="string")return Buffer.from(e,"utf8");if(e instanceof Uint8Array)return e;throw new n("invalid-argument","constructEvent needs the raw request body (a string or a Buffer), not parsed JSON: re-serialised JSON does not reproduce the signed bytes.")}function _(e){let t=typeof e=="string"?[e]:Array.isArray(e)?e:[];if(t.length===0||t.some(e=>typeof e!="string"||e.length===0))throw new n("invalid-argument","at least one non-empty webhook signing secret is required");return t}function v(e){if(typeof e!="string"||e.length===0||e.length>s)throw new p("malformed_header");let t=null,r=[];for(let n of e.split(",")){let e=n.trim(),a=e.indexOf("=");if(a<0)throw new p("malformed_header");let i=e.slice(0,a),o=e.slice(a+1);if(i==="t"){if(t!==null||!u.test(o))throw new p("malformed_header");let e=Number(o);if(!Number.isSafeInteger(e))throw new p("malformed_header");t=e}else i===l&&r.push(o)}if(t===null||r.length===0)throw new p("malformed_header");return{timestamp:t,signatures:r}}function h(e){let t;try{t=JSON.parse(Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("utf8"))}catch{throw new p("malformed_payload")}if(!a(t))throw new p("malformed_payload");let{id:r,object:n,type:i,api_version:o,created:l,livemode:s,data:d}=t;if(typeof r!="string"||r.length===0||n!=="event"||typeof i!="string"||i.length===0||typeof o!="string"||typeof l!="number"||typeof s!="boolean"||!a(d)||!a(d.object))throw new p("malformed_payload");return t}var m=/^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^/?#]*)/;var y="1.5.
|
|
4
|
+
return Object.freeze({ok:false,error:e})}var n=class _EverfurConfigError extends Error{constructor(e,t){super(t),this.name="EverfurConfigError",this.kind=e,Object.setPrototypeOf(this,_EverfurConfigError.prototype)}};function a(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var i="Everfur-Signature",o=300,l="v1",s=4096,d=64,u=/^[0-9]+$/,p=class _EverfurWebhookVerificationError extends Error{constructor(e){super(`Everfur webhook verification failed: ${e}`),this.name="EverfurWebhookVerificationError",this.code=e,Object.setPrototypeOf(this,_EverfurWebhookVerificationError.prototype)}};function constructEvent(t,r,a,i={}){let l=f(t),s=_(a),u=i.toleranceSeconds??o;if(!Number.isInteger(u)||u<0)throw new n("invalid-argument","toleranceSeconds must be a non-negative integer");let m=v(r),y=i.nowSeconds??Math.floor(Date.now()/1e3);if(Math.abs(y-m.timestamp)>u)throw new p("timestamp_outside_tolerance");let b=false;for(let t of s){let r=Buffer.from(c(t,m.timestamp,l),"ascii");for(let t of m.signatures){if(t.length!==d)continue;let n=Buffer.from(t,"utf8");n.length===r.length&&e(r,n)&&(b=true)}}if(!b)throw new p("no_matching_signature");return h(l)}function generateTestSignatureHeader(e){let t=f(e.payload),r=_(e.secrets),a=e.timestamp??Math.floor(Date.now()/1e3);if(!Number.isSafeInteger(a)||a<0)throw new n("invalid-argument","timestamp must be a non-negative integer (unix seconds)");return[`t=${a}`,...r.map(e=>`${l}=${c(e,a,t)}`)].join(",")}function c(e,r,n){return t("sha256",Buffer.from(e,"utf8")).update(`${r}.`,"ascii").update(n).digest("hex")}function f(e){if(typeof e=="string")return Buffer.from(e,"utf8");if(e instanceof Uint8Array)return e;throw new n("invalid-argument","constructEvent needs the raw request body (a string or a Buffer), not parsed JSON: re-serialised JSON does not reproduce the signed bytes.")}function _(e){let t=typeof e=="string"?[e]:Array.isArray(e)?e:[];if(t.length===0||t.some(e=>typeof e!="string"||e.length===0))throw new n("invalid-argument","at least one non-empty webhook signing secret is required");return t}function v(e){if(typeof e!="string"||e.length===0||e.length>s)throw new p("malformed_header");let t=null,r=[];for(let n of e.split(",")){let e=n.trim(),a=e.indexOf("=");if(a<0)throw new p("malformed_header");let i=e.slice(0,a),o=e.slice(a+1);if(i==="t"){if(t!==null||!u.test(o))throw new p("malformed_header");let e=Number(o);if(!Number.isSafeInteger(e))throw new p("malformed_header");t=e}else i===l&&r.push(o)}if(t===null||r.length===0)throw new p("malformed_header");return{timestamp:t,signatures:r}}function h(e){let t;try{t=JSON.parse(Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("utf8"))}catch{throw new p("malformed_payload")}if(!a(t))throw new p("malformed_payload");let{id:r,object:n,type:i,api_version:o,created:l,livemode:s,data:d}=t;if(typeof r!="string"||r.length===0||n!=="event"||typeof i!="string"||i.length===0||typeof o!="string"||typeof l!="number"||typeof s!="boolean"||!a(d)||!a(d.object))throw new p("malformed_payload");return t}var m=/^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^/?#]*)/;var y="1.5.2";var b="2026-09-19",w="EVERFUR_API_BASE_URL";function g(e,t){/* @__PURE__ */
|
|
5
5
|
return Object.freeze({ok:false,failure:/* @__PURE__ */Object.freeze({reason:e,message:t})})}function tryResolveApiBaseUrl(e){let t=e?.trim(),r=t&&t.length>0?t:F(w);return r?k(r):g("missing-api-base-url",`apiBaseUrl is required: pass config.apiBaseUrl or set ${w}. The SDK never ships a hardcoded host.`)}function resolveApiBaseUrl(e){let t=tryResolveApiBaseUrl(e);if(!t.ok)throw new n("invalid-argument",t.failure.message);return t.value}function E(e){return e.slice(e.lastIndexOf("@")+1).replace(/:\d+$/,"").toLowerCase()}function C(e){return e.length===0||e.includes("@")?false:e.startsWith("[")&&e.endsWith("]")?true:!e.includes(":")}function S(e,t){let r=e.indexOf("://");return r<0||e.slice(r+3).includes("@")?false:C(t)}function T(e,t){return`${e}://${t}`}function k(e){let t=e.trim(),r=m.exec(t);if(r===null||r[2]===void 0||r[2].length===0)return g("malformed-api-base-url","apiBaseUrl is not a valid absolute URL");let n=(r[1]??"").toLowerCase(),a=E(r[2]);if(a.length===0)return g("malformed-api-base-url","apiBaseUrl is not a valid absolute URL");let i=S(t,a)?`: ${T(n,a)}`:"";if(n!=="https"){if(!(n==="http"&&D(a)))return n==="http"?g("insecure-api-base-url",`apiBaseUrl must use https (cleartext http is only allowed for localhost)${i}`):g("unsupported-api-base-url-scheme",`apiBaseUrl must be http(s)${i}`)}let o=t.endsWith("/")?t.slice(0,-1):t;/* @__PURE__ */
|
|
6
6
|
return Object.freeze({ok:true,value:o})}function D(e){let t=e.toLowerCase();return t==="localhost"||t==="127.0.0.1"||t==="[::1]"||t==="::1"}function F(e){let t=globalThis.process?.env?.[e];return typeof t=="string"&&t.trim().length>0?t.trim():void 0}var R="server";function I(e){return{"X-Everfur-SDK-Version":y,"X-Everfur-SDK-Platform":R,"X-Everfur-Contract":e}}var N="DAILY_QUOTA_EXCEEDED",O=/* @__PURE__ */new Set(["THROTTLINGEXCEPTION","RATELIMITED","TOOMANYREQUESTS"]);function A(e,t){if(!O.has(e.toUpperCase().replace(/[^A-Z0-9]/g,"")))return e;let r=t,n=r?.daily_limit??r?.error?.daily_limit;return typeof n=="number"&&Number.isFinite(n)?N:e}var j=[{wireCode:"AccessDeniedException",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"AuthorizationException",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"ConflictException",envelope:"http_envelope",httpStatus:409,retryable:true},{wireCode:"DAILY_QUOTA_EXCEEDED",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"FILE_TOO_LARGE",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"IDEMPOTENCY_KEY_IN_FLIGHT",envelope:"http_envelope",httpStatus:409,retryable:true},{wireCode:"IDEMPOTENCY_KEY_REUSED_DIFFERENT_REQUEST",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"INVALID_CONTENT_TYPE",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"InternalFailureException",envelope:"http_envelope",httpStatus:500,retryable:true},{wireCode:"MethodNotAllowedException",envelope:"http_envelope",httpStatus:405,retryable:false},{wireCode:"NotImplementedException",envelope:"http_envelope",httpStatus:501,retryable:false},{wireCode:"PaymentRequiredException",envelope:"http_envelope",httpStatus:402,retryable:false},{wireCode:"ResourceNotFoundException",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"ServiceUnavailableException",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"TIER_UPGRADE_REQUIRED",envelope:"http_envelope",httpStatus:402,retryable:false},{wireCode:"ThrottlingException",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"ValidationException",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"accessDenied",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"access_denied",envelope:"oauth_error",httpStatus:302,retryable:false},{wireCode:"anchor_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"anchor_ref_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"anonTokenInvalid",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"attachment_unreadable",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"authExpired",envelope:"http_envelope",httpStatus:401,retryable:true},{wireCode:"authRejected",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"before_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"bundle_mismatch",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"bundle_not_uploaded",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"bundles_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"catalog_empty_refused",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"catalog_shrink_refused",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"consent_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"consent_required",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"consent_scope_wrong_route",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"device_cipher_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"email_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"endpoint_not_allowed",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"environment_mismatch",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"event_cursor_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_filter_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_id_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"event_payload_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_type_not_available",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_type_unknown",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"idempotency_key_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"idempotency_key_required",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"idempotency_key_reused",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"inbox_cursor_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"insufficientCapability",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"insufficient_scope",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"internal_error",envelope:"sse_frame",httpStatus:200,retryable:false},{wireCode:"invalidRequest",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"invalid_client",envelope:"oauth_error",httpStatus:401,retryable:false},{wireCode:"invalid_client_metadata",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_grant",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_redirect_uri",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_request",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_scope",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_target",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"item_id_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"linked_account_read_only",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"mcp_connection_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"mcp_request_conflict",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"mcp_request_gone",envelope:"http_envelope",httpStatus:410,retryable:false},{wireCode:"mcp_request_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"not_found",envelope:"sse_frame",httpStatus:200,retryable:false},{wireCode:"not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"open_url_not_allowed",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"partner_visit_link_conflict",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"partner_visit_owner_only",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"partner_visit_pet_already_mapped",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"payload_too_large",envelope:"http_envelope",httpStatus:413,retryable:false},{wireCode:"petRefInUse",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"pet_health_list_removals_unconfirmed",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"pet_health_species_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"pet_not_registered",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"provider_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"rateLimited",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"read_target_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"record_species_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"record_subject_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"record_upload_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"records_consent_required",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"restricted_key",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"sandbox_only",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"session_required",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"session_revoked",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"share_limit_reached",envelope:"http_envelope",httpStatus:429,retryable:false},{wireCode:"slow_down",envelope:"oauth_error",httpStatus:429,retryable:true},{wireCode:"species_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"subscription_keys_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"tenant_filter_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"tenant_has_no_capabilities",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"tenant_resource_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"tenant_surface_not_enabled",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"ticket_not_resolved",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"tickets_disabled",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"timeout",envelope:"sse_frame",httpStatus:200,retryable:true},{wireCode:"timezone_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"token_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"unavailable",envelope:"sse_frame",httpStatus:200,retryable:true},{wireCode:"unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"unrestrictedKeyRequired",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"unsupported_grant_type",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"unsupported_response_type",envelope:"oauth_error",httpStatus:302,retryable:false},{wireCode:"user_ref_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"verify_mint_rate_limited",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"verify_mint_refused",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"verify_mint_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"verify_user_ref_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"web_push_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"webhook_endpoint_update_empty",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"webhook_endpoint_update_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"webhook_url_rejected",envelope:"http_envelope",httpStatus:400,retryable:false}],q=/* @__PURE__ */Object.freeze(j.map(e=>/* @__PURE__ */Object.freeze(e)));/* @__PURE__ */Object.freeze(q.map(e=>e.wireCode));var U=/* @__PURE__ */Object.freeze({ValidationException:"validationFailed",AuthorizationException:"authRejected",PaymentRequiredException:"paymentRequired",AccessDeniedException:"accessDenied",ResourceNotFoundException:"resourceNotFound",ConflictException:"conflict",ThrottlingException:"rateLimited",InternalFailureException:"internalError",NotImplementedException:"notImplemented",ServiceUnavailableException:"serviceUnavailable",MethodNotAllowedException:"validationFailed",authExpired:"authExpired",unavailable:"serviceUnavailable",session_required:"sessionRequired",session_revoked:"authExpired",anonTokenInvalid:"authRejected",accessDenied:"accessDenied",invalidRequest:"sdkUpdateRequired",authRejected:"authRejected",rateLimited:"rateLimited",insufficientCapability:"accessDenied",unrestrictedKeyRequired:"accessDenied",user_ref_invalid:"validationFailed",event_cursor_invalid:"validationFailed",event_filter_invalid:"validationFailed",event_payload_invalid:"validationFailed",event_type_unknown:"validationFailed",idempotency_key_invalid:"validationFailed",idempotency_key_required:"validationFailed",idempotency_key_reused:"idempotencyConflict",payload_too_large:"validationFailed",webhook_url_rejected:"validationFailed",webhook_endpoint_update_empty:"validationFailed",webhook_endpoint_update_invalid:"validationFailed",event_type_not_available:"conflict",record_subject_not_found:"resourceNotFound",records_consent_required:"conflict",record_species_unsupported:"validationFailed",record_upload_invalid:"validationFailed",FILE_TOO_LARGE:"validationFailed",INVALID_CONTENT_TYPE:"validationFailed",attachment_unreadable:"validationFailed",provider_unsupported:"validationFailed",token_invalid:"validationFailed",device_cipher_unavailable:"serviceUnavailable",email_invalid:"validationFailed",consent_required:"validationFailed",consent_invalid:"validationFailed",consent_scope_wrong_route:"validationFailed",IDEMPOTENCY_KEY_IN_FLIGHT:"idempotencyInFlight",IDEMPOTENCY_KEY_REUSED_DIFFERENT_REQUEST:"idempotencyConflict",DAILY_QUOTA_EXCEEDED:"quotaExceeded",TIER_UPGRADE_REQUIRED:"paymentRequired",not_found:"conversationNotFound",timeout:"streamTimeout",internal_error:"internalError",invalid_request:"validationFailed",invalid_client:"authRejected",invalid_grant:"authRejected",unsupported_grant_type:"validationFailed",invalid_scope:"validationFailed",invalid_target:"validationFailed",invalid_redirect_uri:"validationFailed",invalid_client_metadata:"validationFailed",unsupported_response_type:"validationFailed",access_denied:"accessDenied",slow_down:"rateLimited",mcp_request_not_found:"resourceNotFound",mcp_request_gone:"resourceNotFound",mcp_connection_not_found:"resourceNotFound",mcp_request_conflict:"conflict",sandbox_only:"accessDenied",tenant_has_no_capabilities:"conflict",verify_mint_refused:"accessDenied",verify_mint_rate_limited:"rateLimited",verify_mint_unavailable:"serviceUnavailable",verify_user_ref_invalid:"validationFailed",insufficient_scope:"accessDenied",tenant_filter_invalid:"validationFailed",tenant_resource_not_found:"resourceNotFound",tenant_surface_not_enabled:"conflict",pet_health_species_unsupported:"validationFailed",pet_health_list_removals_unconfirmed:"validationFailed",petRefInUse:"conflict",share_limit_reached:"conflict",pet_not_registered:"resourceNotFound",species_unsupported:"validationFailed",partner_visit_owner_only:"accessDenied",partner_visit_link_conflict:"conflict",partner_visit_pet_already_mapped:"conflict",linked_account_read_only:"conflict",catalog_empty_refused:"conflict",catalog_shrink_refused:"conflict",endpoint_not_allowed:"validationFailed",event_id_invalid:"validationFailed",inbox_cursor_invalid:"validationFailed",item_id_invalid:"validationFailed",open_url_not_allowed:"validationFailed",read_target_invalid:"validationFailed",subscription_keys_invalid:"validationFailed",web_push_unavailable:"serviceUnavailable",anchor_not_found:"resourceNotFound",anchor_ref_invalid:"validationFailed",before_invalid:"validationFailed",bundle_mismatch:"validationFailed",bundle_not_uploaded:"validationFailed",bundles_unavailable:"serviceUnavailable",environment_mismatch:"validationFailed",restricted_key:"accessDenied",ticket_not_resolved:"conflict",tickets_disabled:"resourceNotFound",timezone_invalid:"validationFailed"}),x=/* @__PURE__ */Object.freeze(q.map(e=>/* @__PURE__ */Object.freeze({wireCode:e.wireCode,envelope:e.envelope,retryable:e.retryable,normalized:U[e.wireCode]}))),L=new Map(x.map(e=>[e.envelope+e.wireCode.toUpperCase(),e])),$=/* @__PURE__ */Object.freeze(["http_envelope",...[...new Set(x.map(e=>e.envelope))].filter(e=>e!=="http_envelope").sort()]);function contractErrorFor(e,t){if(typeof e!="string")return;let r=e.trim().toUpperCase();if(r.length!==0)for(let e of[t??"http_envelope",...$]){let t=L.get(e+r);if(t)return t}}var M=/* @__PURE__ */Object.freeze({authExpired:"authentication",authRejected:"authentication",sessionRequired:"authentication",identitySignatureRequired:"authentication",accessDenied:"authorization",paymentRequired:"entitlement",quotaExceeded:"rateLimit",rateLimited:"rateLimit",validationFailed:"invalidRequest",sdkUpdateRequired:"invalidRequest",runtimeDisposed:"invalidRequest",conversationNotFound:"notFound",petNotFound:"notFound",resourceNotFound:"notFound",conflict:"conflict",idempotencyConflict:"conflict",idempotencyInFlight:"conflict",streamTimeout:"connection",streamIncomplete:"connection",upstreamLlmTimeout:"connection",serviceUnavailable:"connection",internalError:"server",notImplemented:"server",mediaUploadFailed:"media",moderationBlocked:"policy",unknown:"unknown"});function categoryFor(e){return M[e]}function fromWire(e){let t=contractErrorFor(e);if(t)return t.normalized;let r=(e??"").trim().toUpperCase(),n=r.replace(/[^A-Z0-9]/g,"");if(n==="AUTHREJECTED")return"authRejected";if(r.startsWith("AUTH"))return"authExpired";switch(n){case"DAILYQUOTAEXCEEDED":case"QUOTAEXCEEDED":return"quotaExceeded";case"RATELIMITED":case"TOOMANYREQUESTS":case"TELEVETRATELIMITED":return"rateLimited";case"IDEMPOTENCYKEYCONFLICT":case"IDEMPOTENCYCONFLICT":return"idempotencyConflict";case"ACCESSDENIED":case"FORBIDDEN":return"accessDenied";case"IDENTITYSIGNATUREREQUIRED":return"identitySignatureRequired";case"FREECAPREACHED":return"paymentRequired";case"RUNTIMEDISPOSED":return"runtimeDisposed";case"NOTFOUND":case"CONVERSATIONNOTFOUND":return"conversationNotFound";case"PETNOTFOUND":return"petNotFound";case"TIMEOUT":case"STREAMTIMEOUT":return"streamTimeout";case"MEDIAUPLOADFAILED":case"UNRECOGNIZEDVIDEOFORMAT":case"FILETOOSMALL":return"mediaUploadFailed";case"MODERATIONBLOCKED":return"moderationBlocked";case"UPSTREAMLLMTIMEOUT":return"upstreamLlmTimeout";case"INTERNALERROR":case"INTERNALSERVERERROR":return"internalError";case"STREAMINCOMPLETE":case"CHATSTREAMINCOMPLETE":return"streamIncomplete";case"INVALIDANALYSISTYPE":case"INVALIDUPLOADPURPOSE":return"unknown";default:return"unknown"}}function fromHttpStatus(e){return e===401?"authExpired":e===403?"accessDenied":e===404?"conversationNotFound":e===409?"idempotencyConflict":e===421?"unknown":e===429?"rateLimited":e===400||e===422?"unknown":e>=500?"internalError":"unknown"}var P=/* @__PURE__ */new Set(["streamTimeout","rateLimited","internalError","upstreamLlmTimeout","streamIncomplete"]);function isAutoRetryable(e){return P.has(e)}var z=/* @__PURE__ */new Set(["serviceUnavailable","conflict","idempotencyInFlight"]);function isRetryableCode(e){return isAutoRetryable(e)||z.has(e)}var Y="This feature isn't available on your account right now.",V="Something in that request was not right. Check the details and try again.",B=/* @__PURE__ */Object.freeze({authExpired:"Please sign in again to continue.",authRejected:"Please sign in again to continue.",sessionRequired:"This app needs to be updated to keep using Everfur.",accessDenied:Y,paymentRequired:"This is part of a paid plan.",quotaExceeded:"You have used today's messages. This resets tomorrow.",rateLimited:"You are sending messages quickly. Try again in a few seconds.",validationFailed:V,sdkUpdateRequired:"This app needs to be updated to keep using Everfur.",conflict:"That is already running. Wait for it to finish, then try again.",idempotencyConflict:"That message was already delivered.",idempotencyInFlight:"That is still processing. Give it a moment.",conversationNotFound:"This conversation is no longer available.",petNotFound:"We could not find that pet. Please pick a pet and try again.",resourceNotFound:"We could not find that.",streamTimeout:"The response timed out. Tap retry to try again.",mediaUploadFailed:"We could not upload that photo. Please attach it again.",moderationBlocked:"This request cannot be answered here.",upstreamLlmTimeout:"The response timed out. Tap retry to try again.",internalError:"We hit a snag on our end. Please try again.",notImplemented:"That is not available yet.",serviceUnavailable:"That service is briefly unavailable. Try again shortly.",streamIncomplete:"The connection dropped mid-answer. Tap retry to continue.",identitySignatureRequired:Y,runtimeDisposed:V,unknown:"Something went wrong. Please try again."}),K="This session has ended. Please sign in again.",W="linked_account_read_only";function Q(e,t,r){return e==="conflict"&&r===W?Y:(e==="authRejected"||e==="authExpired")&&typeof t=="string"&&t.trim().toLowerCase()==="session_revoked"?K:userFacingError(e)}function userFacingError(e){return B[e]}function G(e,t,r){Object.defineProperty(e,t,{value:r,enumerable:false,writable:false,configurable:false})}var Z=/^[a-z][a-z0-9_]{0,63}$/;function makeEverfurError(e,t){let r=contractErrorFor(t?.wireCode,t?.wireEnvelope),n=e==="conflict"&&t?.reasonCode===W,a={code:e,category:categoryFor(e),retryable:t?.retryable??(n?false:isRetryableCode(e)),displayMessage:Q(e,t?.wireCode,n?W:null)};t?.httpStatus!==void 0&&(a.httpStatus=t.httpStatus),t?.requestId&&(a.requestId=t.requestId),typeof t?.reasonCode=="string"&&Z.test(t.reasonCode)&&(a.reasonCode=t.reasonCode);let i=t?.retryAfterSeconds;if(typeof i=="number"&&Number.isFinite(i)&&i>=0&&(a.retryAfterSeconds=Math.round(i)),r);return t?.wireMessage&&G(a,"wireMessage",t.wireMessage),t?.raw!==void 0&&t.raw!==null&&G(a,"raw",t.raw),/* @__PURE__ */Object.freeze(a)}var X="free_cap_reached";function H(e){return typeof e=="number"&&Number.isInteger(e)&&e>=0?e:null}function J(e){if(typeof e!="object"||e===null)return null;let t=e,r=t.detail,n=typeof r=="object"&&r!==null?r:t;if(n.error!==X&&n.code!==X)return null;let a=H(n.limit),i=H(n.used);if(a===null||i===null)return null;let o=n.resets_at,l=n.emergency_guidance;/* @__PURE__ */
|
|
7
7
|
return Object.freeze({limit:a,used:i,resetsAt:typeof o=="string"&&o.length>0?o:null,...typeof l=="string"&&l.trim().length>0?{emergencyGuidance:l}:{}})}function ee(e,t){if(e.status!==429&&e.status!==503)return t;let r=re(e.headers.get(te),Date.now());if(r===null)return t;let n=t!==null&&typeof t=="object"&&!Array.isArray(t)?t:null;return n!==null&&ne(n)?t:{...n??{},retry_after_seconds:r}}var te="retry-after";function re(e,t){if(e===null)return null;let r=e.trim();if(/^\d+$/.test(r))return Number(r);let n=Date.parse(r);return Number.isFinite(n)?Math.max(0,Math.ceil((n-t)/1e3)):null}function ne(e){return[e,e.error,e.detail].some(e=>e!==null&&typeof e=="object"&&("retry_after_seconds"in e||"resets_at"in e))}var ae="x-request-id";function errorFromResponse(e,t,r){let n=le(t),a=n?fromWire(n):fromHttpStatus(e),i=se(t);return makeEverfurError(a,{httpStatus:e,...de(t)?{retryable:true}:{},...r?{requestId:r}:{},...n?{wireCode:n}:{},...oe(t)?{reasonCode:oe(t)}:{},...ie(t)!==null?{retryAfterSeconds:ie(t)}:{},...i?{wireMessage:i}:{},...t!=null?{raw:t}:{}})}function ie(e){let t=e,r=t?.retry_after_seconds??t?.error?.retry_after_seconds;return typeof r=="number"&&Number.isFinite(r)&&r>=0?r:null}function networkError(e){return makeEverfurError("internalError",{retryable:true,wireMessage:ue(e)})}function requestIdOf(e){let t=e.headers.get(ae);return typeof t=="string"&&t.length>0?t:null}function getGlobalFetch(){let e=globalThis.fetch;if(typeof e!="function")throw new n("missing-peer-dependency","global fetch is unavailable; provide config.transport or an injected fetch implementation");return e}function oe(e){let t=e,r=t?.error?.reason_code??t?.reason_code;return typeof r=="string"&&r.length>0?r:null}function le(e){let t=e,r=t?.error?.code??t?.code;return typeof r=="string"&&r.length>0?A(r,e):J(e)!==null?X:null}function se(e){let t=e,r=t?.error?.message??t?.message;return typeof r=="string"&&r.length>0?r:null}function de(e){let t=e;return t?.error?.retryable===true||t?.retryable===true}function ue(e){return e instanceof Error?e.message:typeof e=="string"?e:"network request failed"}var pe=/* @__PURE__ */Object.freeze(["member.linked","member.unlinked","visit.booked","visit.cancelled","visit.completed","visit.no_show","record_request.updated","record.ready","webhook_endpoint.test","chat.follow_up_due","chat.urgency.flagged","pet.vaccination.due","visit.rescheduled","visit.reminder","visit.followup_sent","chat.reminder_due","record.activation","visit.message_received","visit.ended","contact.exported","health_plan.box_due","health_plan.one_box_ordered","claim.evidence_returned","claim.evidence_updated","claim.records_requested","claim.failed","claim.duplicate","claim.decided","claim.inbound_refused","insured_pet.profile.ready","insured_pet.profile.updated","chat.engagement_message","visit.notes_ready","visit.vet_joined","visit.summary_sent","chat.answer_ready","chat.follow_up_day5_due","care.medication_check_due","care.dose_due","care.refill_due","care.prevention_due","care.meal_due","care.nose_to_tail_due","care.reminder_due","record.labs_ready","record.update_available","order.updated","order.prescription_updated","walk.reminder","walk.reminder_offer","weather.heat","weather.storm","weather.air_quality","weather.ice","weather.pollen","safety.danger_day","safety.food_recall","insight.week","insight.birthday","tip.weekly","tip.daily","insight.weight_trend","tip.question_guide","insight.monthly_notes","pet.adoption_day","insight.year_summary","pack.walk_logged","pack.question","pack.reactions","pack.care_handoff","pack.photo_ready","mood.check_in_due","streak.at_risk","streak.milestone","membership.first_visit","membership.renewal","membership.invite","support.replied"]),ce=/* @__PURE__ */Object.freeze(["member.linked","member.unlinked","chat.urgency.flagged","webhook_endpoint.test","contact.exported","health_plan.box_due","health_plan.one_box_ordered","claim.evidence_returned","claim.evidence_updated","claim.records_requested","claim.failed","claim.duplicate","claim.decided","claim.inbound_refused","insured_pet.profile.ready","insured_pet.profile.updated"]);function isEverfurWebhookEventType(e){return typeof e=="string"&&pe.includes(e)}function isEverfurWebhookEvent(e){return isEverfurWebhookEventType(e.type)}var fe=/* @__PURE__ */Object.freeze(["pet.profile.updated","pet.incident.reported","pet.behavior_note.added","pet.service_score.recorded","pet.deleted","member.status_changed","member.deleted"]);var _e=["sk_partner_","rk_partner_"];function ve(e,t){if(typeof e!="string"||e.length===0)throw new n("invalid-argument","partnerSecretKey is required");if(e.startsWith("pk_"))throw new n("invalid-argument",`partnerSecretKey is a publishable key (pk_...): ${t} needs your secret key, server side only`);if(!_e.some(t=>e.startsWith(t)))throw new n("invalid-argument","partnerSecretKey must be an sk_partner_ secret key or an rk_partner_ restricted key")}var he=128;function assertValidUserRef(e){let t=typeof e=="string"?[...e].length:0;if(typeof e!="string"||t<1||t>he)throw new n("invalid-argument",`user_ref must be 1..${he} characters`);if(e.trim().length===0)throw new n("invalid-argument","user_ref must not be blank: the server strips surrounding whitespace before validating, so a whitespace-only value arrives empty and is rejected as required.");if(e!==e.trim())throw new n("invalid-argument","user_ref must not have leading or trailing whitespace: the server strips it, so padded and unpadded forms of the same id resolve to ONE user. Pass the exact id you want to key on.");if(e.includes("@"))throw new n("invalid-argument","user_ref must not contain '@'");if(!me(e))throw new n("invalid-argument","user_ref must be printable (no control characters)");return e}function me(e){return!ye.test(e)}var ye=/[\p{Cc}\p{Cf}\p{Cs}\p{Co}\p{Cn}\p{Zl}\p{Zp}]|(?!\u0020)[\p{Zs}]/u;function be(e){for(let t=0;t<e.length;t+=1){let r=e.charCodeAt(t);if(r>=55296&&r<=56319){let r=e.charCodeAt(t+1);if(!(r>=56320&&r<=57343))return true;t+=1}else if(r>=56320&&r<=57343)return true}return false}function we(e){return[...e].length}var ge=/* @__PURE__ */Object.freeze({dog:"dog",canine:"dog",k9:"dog",puppy:"dog",cat:"cat",feline:"cat",kitten:"cat"});function canonicalPetSpecies(e){if(typeof e!="string")return null;let t=e.trim().toLowerCase();return Object.prototype.hasOwnProperty.call(ge,t)?ge[t]:null}var Ee=50,Ce=128,Se=120,Te=120,ke=2e3,De=120,Fe=80,Re=/* @__PURE__ */new Set(["male","female","unknown"]),Ie=/* @__PURE__ */new Set(["day","month","year"]),Ne=/* @__PURE__ */new Set(["low","medium","high","athletic"]),Oe=/* @__PURE__ */new Set(["indoor","outdoor","both"]),Ae=/* @__PURE__ */new Set(["mild","moderate","severe"]),je=/^(\d{4})-(\d{2})-(\d{2})$/,qe=[["sex","sex"],["spayedNeutered","spayed_neutered"],["birthDate","birth_date"],["birthDatePrecision","birth_date_precision"],["activityLevel","activity_level"],["indoorOutdoor","indoor_outdoor"],["foodBrand","food_brand"],["foodType","food_type"],["microchipId","microchip_id"]],Ue=[["allergies","allergies"],["medications","medications"],["supplements","supplements"],["conditions","conditions"]];/* @__PURE__ */Object.freeze([...qe,...Ue].map(([e])=>e));function xe(e){let t=je.exec(e);if(t===null)return false;let[r,n,a]=[Number(t[1]),Number(t[2]),Number(t[3])],i=new Date(Date.UTC(r,n-1,a));return i.getUTCFullYear()===r&&i.getUTCMonth()===n-1&&i.getUTCDate()===a}var Le=e=>(t,r)=>typeof r=="string"&&e.has(r)?null:`${t} must be one of ${[...e].join(", ")}`,$e=(e,t)=>typeof t=="boolean"?null:`${e} must be true or false`,Me=(e,t)=>typeof t=="string"&&xe(t)?null:`${e} must be a real date written YYYY-MM-DD`,Pe=(e,t={})=>(r,n)=>{if(typeof n!="string")return`${r} must be a string`;if(be(n))return`${r} contains an unpaired surrogate and cannot be encoded`;let a=t.trimmed?n.trim():n;if(t.required&&a.length===0)return`${r} is required and must not be blank`;let i=we(a);return i<=e?null:`${r} is ${i} characters; the server accepts at most ${e}`},ze={sex:Le(Re),spayedNeutered:$e,birthDate:Me,birthDatePrecision:Le(Ie),activityLevel:Le(Ne),indoorOutdoor:Le(Oe),foodBrand:Pe(De),foodType:Pe(De),microchipId:Pe(Fe)},Ye=["ref","ref",false,Pe(Ce,{required:true,trimmed:true})],Ve=["notes","notes",false,Pe(ke,{trimmed:true})],Be=[Ye,["name","name",true,Pe(Se,{required:true,trimmed:true})],["dose","dose",false,Pe(Te,{trimmed:true})],["frequency","frequency",false,Pe(Te,{trimmed:true})],["startDate","start_date",false,Me],["endDate","end_date",false,Me],Ve],Ke={allergies:[Ye,["allergen","allergen",true,Pe(Se,{required:true,trimmed:true})],["severity","severity",false,Le(Ae)],Ve],medications:Be,supplements:Be,conditions:[Ye,["conditionName","condition_name",true,Pe(Se,{required:true,trimmed:true})],["diagnosedDate","diagnosed_date",false,Me],Ve]};function We(e,t,r){let n=`${e}[${t}]`;if(typeof r!="object"||r===null||Array.isArray(r))return{error:`${n} must be an object`};let a=r,i={};for(let[t,r,o,l]of Ke[e]){let e=a[t];if(e==null){if(o)return{error:`${n}.${t} is required`};e===null&&(i[r]=null);continue}let s=l(`${n}.${t}`,e);if(s!==null)return{error:s};i[r]=e}let o=i.start_date,l=i.end_date;return typeof o=="string"&&typeof l=="string"&&l<o?{error:`${n}.endDate must not be before startDate`}:{item:i}}function Qe(e,t){if(!Array.isArray(t))return{error:`${e} must be an array (send [] to clear it)`};if(t.length>Ee)return{error:`${e} has ${t.length} items; the server accepts at most ${Ee}`};let r=[],n=/* @__PURE__ */new Set;for(let a=0;a<t.length;a+=1){let i=We(e,a,t[a]);if("error"in i)return i;let o=i.item.ref;if(typeof o=="string"){let t=o.trim();if(n.has(t))return{error:`${e}: ref ${JSON.stringify(t)} is used twice; a ref names one item`};n.add(t)}r.push(i.item)}return{items:r}}function Ge(e,t){let r=e,n={};for(let[e,t]of qe){let a=r[e];if(a!==void 0){if(a!==null){let t=ze[e](e,a);if(t!==null)return{error:t}}n[t]=a}}let a=r.birthDate!==void 0,i=r.birthDatePrecision!==void 0;if(a!==i||a&&r.birthDate===null!=(r.birthDatePrecision===null))return{error:"birthDate and birthDatePrecision must be sent together, both set or both null"};for(let[e,t]of Ue){let a=r[e];if(a===void 0)continue;let i=Qe(e,a);if("error"in i)return i;n[t]=i.items}return Object.keys(n).length>0&&t!==void 0&&canonicalPetSpecies(t)===null?{error:"health fields need a pet Everfur reads as a dog or a cat (dog, canine, k9, puppy, cat, feline, kitten)"}:{body:n}}var Ze=[["name","name"],["species","species"],["breed","breed"],["ageYears","age_years"],["weightKg","weight_kg"],["partnerLabelInstructions","partner_label_instructions"]];function Xe(e){if(typeof e!="object"||e===null||Array.isArray(e))throw new n("invalid-argument","the pet profile must be an object");let t={};for(let[r,n]of Ze)e[r]!==void 0&&(t[n]=e[r]);let r=Ge(e,e.species);if("error"in r)throw new n("invalid-argument",r.error);return Object.assign(t,r.body)}var He=/^[\x21-\x7e]{1,255}$/,Je=32*1024,et=/^\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:[Zz]|[+-]\d{2}:?\d{2})$/,tt=3e4,rt=/* @__PURE__ */Object.freeze({"pet.profile.updated":{subject:"pet",schemaVersions:[1,2]},"pet.incident.reported":{subject:"pet",schemaVersions:[1]},"pet.behavior_note.added":{subject:"pet",schemaVersions:[1]},"pet.service_score.recorded":{subject:"pet",schemaVersions:[1]},"pet.deleted":{subject:"pet",schemaVersions:[1]},"member.status_changed":{subject:"member",schemaVersions:[1]},"member.deleted":{subject:"member",schemaVersions:[1]}});async function sendPartnerEvent(e,t,a){let i=a??r();if(typeof i!="string"||!He.test(i))throw new n("invalid-argument","idempotencyKey must be 1 to 255 visible ASCII characters (no spaces, no control or non-ASCII characters)");ve(e.partnerSecretKey,"sending events");let o=lt(at(t)),l=e.fetchImpl??getGlobalFetch(),s=`${resolveApiBaseUrl(e.apiBaseUrl)}/partners/events`,d={...I(e.contractVersion??b),accept:"application/json","content-type":"application/json","idempotency-key":i,"x-everfur-partner-secret-key":e.partnerSecretKey},u=new AbortController,p=setTimeout(()=>u.abort(),tt),c;try{c=await l(s,{method:"POST",headers:d,body:o,signal:u.signal})}catch(e){return err(networkError(e))}finally{clearTimeout(p)}let f=null;try{f=await c.json()}catch{f=null}let _=requestIdOf(c);if(!c.ok)return err(errorFromResponse(c.status,ee(c,f),_));let v=st(f,i);return v?ok(v):err(errorFromResponse(502,{error:{code:"INTERNAL_ERROR"}},_))}function nt(e){return typeof e=="string"&&fe.includes(e)}function at(e){if(typeof e!="object"||e===null)throw new n("invalid-argument","event is required");if(!nt(e.type))throw new n("invalid-argument",`event.type must be one of ${fe.join(", ")}`);let t=rt[e.type],r=e.schemaVersion??1;if(typeof r!="number"||!t.schemaVersions.includes(r))throw new n("invalid-argument",`event.schemaVersion must be one of ${t.schemaVersions.join(", ")} for ${e.type}`);let userRef=assertValidUserRef(e.userRef);if(t.subject==="pet"&&e.petRef===void 0)throw new n("invalid-argument",`event.petRef is required for ${e.type}`);if(t.subject==="member"&&e.petRef!==void 0)throw new n("invalid-argument",`event.petRef is not accepted on ${e.type}`);let petRef=e.petRef===void 0?void 0:it(e.petRef);if(typeof e.data!="object"||e.data===null||Array.isArray(e.data))throw new n("invalid-argument","event.data must be an object");let a=e.type==="pet.profile.updated"&&r===2?Xe(e.data):e.data,i={type:e.type,schema_version:r,user_ref:userRef,occurred_at:ot(e.occurredAt),data:a};return petRef!==void 0&&(i.pet_ref=petRef),i}function it(e){try{return assertValidUserRef(e)}catch(e){throw e instanceof n?new n("invalid-argument",`event.petRef follows the user_ref rule: ${e.message}`):e}}function ot(e){if(typeof e=="string"&&!et.test(e))throw new n("invalid-argument","event.occurredAt must be a Date or an ISO 8601 date-time with an explicit offset (Z or +05:30)");let t=e instanceof Date?e:typeof e=="string"?new Date(e):new Date(Number.NaN);if(Number.isNaN(t.getTime()))throw new n("invalid-argument","event.occurredAt must be a Date or an ISO 8601 date-time with an explicit offset (Z or +05:30)");return t.toISOString()}function lt(e){let t;try{t=JSON.stringify(e)}catch{throw new n("invalid-argument","event.data must be JSON-serialisable")}let r=(new TextEncoder).encode(t).byteLength;if(r>Je)throw new n("invalid-argument",`the event is ${r} bytes once serialised; Everfur accepts at most ${Je} (32 KB)`);return t}function st(e,t){if(typeof e!="object"||e===null)return null;let r=e,n=r.id,a=r.type,i=r.schema_version,userRef=r.user_ref,petRef=r.pet_ref??null,o=r.occurred_at,l=r.received_at,s=r.status,d=r.livemode;return typeof n!="string"||n.length===0||!nt(a)||typeof i!="number"||typeof userRef!="string"||petRef!==null&&typeof petRef!="string"||typeof o!="string"||typeof l!="string"||typeof s!="string"||typeof d!="boolean"?null:/* @__PURE__ */Object.freeze({id:n,type:a,schemaVersion:i,userRef:userRef,petRef:petRef,occurredAt:o,receivedAt:l,status:s,livemode:d,idempotencyKey:t})}export{o as DEFAULT_WEBHOOK_TOLERANCE_SECONDS,i as EVERFUR_SIGNATURE_HEADER,pe as EVERFUR_WEBHOOK_EVENT_TYPES,ce as EVERFUR_WEBHOOK_ONLY_EVENT_TYPES,p as EverfurWebhookVerificationError,fe as PARTNER_INBOUND_EVENT_TYPES,constructEvent,generateTestSignatureHeader,isEverfurWebhookEvent,isEverfurWebhookEventType,sendPartnerEvent};
|
package/dist/server/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*! @everfur/sdk. Copyright (c) 2026 Strand Health Inc. dba Everfur. All rights reserved. Use is subject to the Everfur SDK License: https://docs.everfur.com/license */
|
|
2
2
|
"use strict";function ok(e,t){/* @__PURE__ */
|
|
3
3
|
return Object.freeze({ok:true,value:e})}function err(e){/* @__PURE__ */
|
|
4
|
-
return Object.freeze({ok:false,error:e})}var e=class _EverfurConfigError extends Error{constructor(e,t){super(t),this.name="EverfurConfigError",this.kind=e,Object.setPrototypeOf(this,_EverfurConfigError.prototype)}};var t=/^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^/?#]*)/;var r="1.5.
|
|
4
|
+
return Object.freeze({ok:false,error:e})}var e=class _EverfurConfigError extends Error{constructor(e,t){super(t),this.name="EverfurConfigError",this.kind=e,Object.setPrototypeOf(this,_EverfurConfigError.prototype)}};var t=/^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^/?#]*)/;var r="1.5.2";var n="2026-09-19",a="EVERFUR_API_BASE_URL";function i(e,t){/* @__PURE__ */
|
|
5
5
|
return Object.freeze({ok:false,failure:/* @__PURE__ */Object.freeze({reason:e,message:t})})}function tryResolveApiBaseUrl(e){let t=e?.trim(),r=t&&t.length>0?t:c(a);return r?d(r):i("missing-api-base-url",`apiBaseUrl is required: pass config.apiBaseUrl or set ${a}. The SDK never ships a hardcoded host.`)}function resolveApiBaseUrl(t){let r=tryResolveApiBaseUrl(t);if(!r.ok)throw new e("invalid-argument",r.failure.message);return r.value}function o(e){return e.slice(e.lastIndexOf("@")+1).replace(/:\d+$/,"").toLowerCase()}function l(e){return e.length===0||e.includes("@")?false:e.startsWith("[")&&e.endsWith("]")?true:!e.includes(":")}function s(e,t){let r=e.indexOf("://");return r<0||e.slice(r+3).includes("@")?false:l(t)}function u(e,t){return`${e}://${t}`}function d(e){let r=e.trim(),n=t.exec(r);if(n===null||n[2]===void 0||n[2].length===0)return i("malformed-api-base-url","apiBaseUrl is not a valid absolute URL");let a=(n[1]??"").toLowerCase(),l=o(n[2]);if(l.length===0)return i("malformed-api-base-url","apiBaseUrl is not a valid absolute URL");let d=s(r,l)?`: ${u(a,l)}`:"";if(a!=="https"){if(!(a==="http"&&p(l)))return a==="http"?i("insecure-api-base-url",`apiBaseUrl must use https (cleartext http is only allowed for localhost)${d}`):i("unsupported-api-base-url-scheme",`apiBaseUrl must be http(s)${d}`)}let c=r.endsWith("/")?r.slice(0,-1):r;/* @__PURE__ */
|
|
6
6
|
return Object.freeze({ok:true,value:c})}function p(e){let t=e.toLowerCase();return t==="localhost"||t==="127.0.0.1"||t==="[::1]"||t==="::1"}function c(e){let t=globalThis.process?.env?.[e];return typeof t=="string"&&t.trim().length>0?t.trim():void 0}var f="server";function v(e){return{"X-Everfur-SDK-Version":r,"X-Everfur-SDK-Platform":f,"X-Everfur-Contract":e}}var _="DAILY_QUOTA_EXCEEDED",h=/* @__PURE__ */new Set(["THROTTLINGEXCEPTION","RATELIMITED","TOOMANYREQUESTS"]);function m(e,t){if(!h.has(e.toUpperCase().replace(/[^A-Z0-9]/g,"")))return e;let r=t,n=r?.daily_limit??r?.error?.daily_limit;return typeof n=="number"&&Number.isFinite(n)?_:e}var y=[{wireCode:"AccessDeniedException",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"AuthorizationException",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"ConflictException",envelope:"http_envelope",httpStatus:409,retryable:true},{wireCode:"DAILY_QUOTA_EXCEEDED",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"FILE_TOO_LARGE",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"IDEMPOTENCY_KEY_IN_FLIGHT",envelope:"http_envelope",httpStatus:409,retryable:true},{wireCode:"IDEMPOTENCY_KEY_REUSED_DIFFERENT_REQUEST",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"INVALID_CONTENT_TYPE",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"InternalFailureException",envelope:"http_envelope",httpStatus:500,retryable:true},{wireCode:"MethodNotAllowedException",envelope:"http_envelope",httpStatus:405,retryable:false},{wireCode:"NotImplementedException",envelope:"http_envelope",httpStatus:501,retryable:false},{wireCode:"PaymentRequiredException",envelope:"http_envelope",httpStatus:402,retryable:false},{wireCode:"ResourceNotFoundException",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"ServiceUnavailableException",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"TIER_UPGRADE_REQUIRED",envelope:"http_envelope",httpStatus:402,retryable:false},{wireCode:"ThrottlingException",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"ValidationException",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"accessDenied",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"access_denied",envelope:"oauth_error",httpStatus:302,retryable:false},{wireCode:"anchor_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"anchor_ref_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"anonTokenInvalid",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"attachment_unreadable",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"authExpired",envelope:"http_envelope",httpStatus:401,retryable:true},{wireCode:"authRejected",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"before_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"bundle_mismatch",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"bundle_not_uploaded",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"bundles_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"catalog_empty_refused",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"catalog_shrink_refused",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"consent_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"consent_required",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"consent_scope_wrong_route",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"device_cipher_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"email_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"endpoint_not_allowed",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"environment_mismatch",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"event_cursor_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_filter_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_id_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"event_payload_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_type_not_available",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_type_unknown",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"idempotency_key_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"idempotency_key_required",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"idempotency_key_reused",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"inbox_cursor_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"insufficientCapability",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"insufficient_scope",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"internal_error",envelope:"sse_frame",httpStatus:200,retryable:false},{wireCode:"invalidRequest",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"invalid_client",envelope:"oauth_error",httpStatus:401,retryable:false},{wireCode:"invalid_client_metadata",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_grant",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_redirect_uri",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_request",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_scope",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_target",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"item_id_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"linked_account_read_only",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"mcp_connection_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"mcp_request_conflict",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"mcp_request_gone",envelope:"http_envelope",httpStatus:410,retryable:false},{wireCode:"mcp_request_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"not_found",envelope:"sse_frame",httpStatus:200,retryable:false},{wireCode:"not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"open_url_not_allowed",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"partner_visit_link_conflict",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"partner_visit_owner_only",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"partner_visit_pet_already_mapped",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"payload_too_large",envelope:"http_envelope",httpStatus:413,retryable:false},{wireCode:"petRefInUse",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"pet_health_list_removals_unconfirmed",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"pet_health_species_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"pet_not_registered",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"provider_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"rateLimited",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"read_target_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"record_species_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"record_subject_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"record_upload_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"records_consent_required",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"restricted_key",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"sandbox_only",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"session_required",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"session_revoked",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"share_limit_reached",envelope:"http_envelope",httpStatus:429,retryable:false},{wireCode:"slow_down",envelope:"oauth_error",httpStatus:429,retryable:true},{wireCode:"species_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"subscription_keys_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"tenant_filter_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"tenant_has_no_capabilities",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"tenant_resource_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"tenant_surface_not_enabled",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"ticket_not_resolved",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"tickets_disabled",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"timeout",envelope:"sse_frame",httpStatus:200,retryable:true},{wireCode:"timezone_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"token_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"unavailable",envelope:"sse_frame",httpStatus:200,retryable:true},{wireCode:"unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"unrestrictedKeyRequired",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"unsupported_grant_type",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"unsupported_response_type",envelope:"oauth_error",httpStatus:302,retryable:false},{wireCode:"user_ref_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"verify_mint_rate_limited",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"verify_mint_refused",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"verify_mint_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"verify_user_ref_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"web_push_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"webhook_endpoint_update_empty",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"webhook_endpoint_update_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"webhook_url_rejected",envelope:"http_envelope",httpStatus:400,retryable:false}],b=/* @__PURE__ */Object.freeze(y.map(e=>/* @__PURE__ */Object.freeze(e)));/* @__PURE__ */Object.freeze(b.map(e=>e.wireCode));var g=/* @__PURE__ */Object.freeze({ValidationException:"validationFailed",AuthorizationException:"authRejected",PaymentRequiredException:"paymentRequired",AccessDeniedException:"accessDenied",ResourceNotFoundException:"resourceNotFound",ConflictException:"conflict",ThrottlingException:"rateLimited",InternalFailureException:"internalError",NotImplementedException:"notImplemented",ServiceUnavailableException:"serviceUnavailable",MethodNotAllowedException:"validationFailed",authExpired:"authExpired",unavailable:"serviceUnavailable",session_required:"sessionRequired",session_revoked:"authExpired",anonTokenInvalid:"authRejected",accessDenied:"accessDenied",invalidRequest:"sdkUpdateRequired",authRejected:"authRejected",rateLimited:"rateLimited",insufficientCapability:"accessDenied",unrestrictedKeyRequired:"accessDenied",user_ref_invalid:"validationFailed",event_cursor_invalid:"validationFailed",event_filter_invalid:"validationFailed",event_payload_invalid:"validationFailed",event_type_unknown:"validationFailed",idempotency_key_invalid:"validationFailed",idempotency_key_required:"validationFailed",idempotency_key_reused:"idempotencyConflict",payload_too_large:"validationFailed",webhook_url_rejected:"validationFailed",webhook_endpoint_update_empty:"validationFailed",webhook_endpoint_update_invalid:"validationFailed",event_type_not_available:"conflict",record_subject_not_found:"resourceNotFound",records_consent_required:"conflict",record_species_unsupported:"validationFailed",record_upload_invalid:"validationFailed",FILE_TOO_LARGE:"validationFailed",INVALID_CONTENT_TYPE:"validationFailed",attachment_unreadable:"validationFailed",provider_unsupported:"validationFailed",token_invalid:"validationFailed",device_cipher_unavailable:"serviceUnavailable",email_invalid:"validationFailed",consent_required:"validationFailed",consent_invalid:"validationFailed",consent_scope_wrong_route:"validationFailed",IDEMPOTENCY_KEY_IN_FLIGHT:"idempotencyInFlight",IDEMPOTENCY_KEY_REUSED_DIFFERENT_REQUEST:"idempotencyConflict",DAILY_QUOTA_EXCEEDED:"quotaExceeded",TIER_UPGRADE_REQUIRED:"paymentRequired",not_found:"conversationNotFound",timeout:"streamTimeout",internal_error:"internalError",invalid_request:"validationFailed",invalid_client:"authRejected",invalid_grant:"authRejected",unsupported_grant_type:"validationFailed",invalid_scope:"validationFailed",invalid_target:"validationFailed",invalid_redirect_uri:"validationFailed",invalid_client_metadata:"validationFailed",unsupported_response_type:"validationFailed",access_denied:"accessDenied",slow_down:"rateLimited",mcp_request_not_found:"resourceNotFound",mcp_request_gone:"resourceNotFound",mcp_connection_not_found:"resourceNotFound",mcp_request_conflict:"conflict",sandbox_only:"accessDenied",tenant_has_no_capabilities:"conflict",verify_mint_refused:"accessDenied",verify_mint_rate_limited:"rateLimited",verify_mint_unavailable:"serviceUnavailable",verify_user_ref_invalid:"validationFailed",insufficient_scope:"accessDenied",tenant_filter_invalid:"validationFailed",tenant_resource_not_found:"resourceNotFound",tenant_surface_not_enabled:"conflict",pet_health_species_unsupported:"validationFailed",pet_health_list_removals_unconfirmed:"validationFailed",petRefInUse:"conflict",share_limit_reached:"conflict",pet_not_registered:"resourceNotFound",species_unsupported:"validationFailed",partner_visit_owner_only:"accessDenied",partner_visit_link_conflict:"conflict",partner_visit_pet_already_mapped:"conflict",linked_account_read_only:"conflict",catalog_empty_refused:"conflict",catalog_shrink_refused:"conflict",endpoint_not_allowed:"validationFailed",event_id_invalid:"validationFailed",inbox_cursor_invalid:"validationFailed",item_id_invalid:"validationFailed",open_url_not_allowed:"validationFailed",read_target_invalid:"validationFailed",subscription_keys_invalid:"validationFailed",web_push_unavailable:"serviceUnavailable",anchor_not_found:"resourceNotFound",anchor_ref_invalid:"validationFailed",before_invalid:"validationFailed",bundle_mismatch:"validationFailed",bundle_not_uploaded:"validationFailed",bundles_unavailable:"serviceUnavailable",environment_mismatch:"validationFailed",restricted_key:"accessDenied",ticket_not_resolved:"conflict",tickets_disabled:"resourceNotFound",timezone_invalid:"validationFailed"}),w=/* @__PURE__ */Object.freeze(b.map(e=>/* @__PURE__ */Object.freeze({wireCode:e.wireCode,envelope:e.envelope,retryable:e.retryable,normalized:g[e.wireCode]}))),S=new Map(w.map(e=>[e.envelope+e.wireCode.toUpperCase(),e])),C=/* @__PURE__ */Object.freeze(["http_envelope",...[...new Set(w.map(e=>e.envelope))].filter(e=>e!=="http_envelope").sort()]);function contractErrorFor(e,t){if(typeof e!="string")return;let r=e.trim().toUpperCase();if(r.length!==0)for(let e of[t??"http_envelope",...C]){let t=S.get(e+r);if(t)return t}}var E=/* @__PURE__ */Object.freeze({authExpired:"authentication",authRejected:"authentication",sessionRequired:"authentication",identitySignatureRequired:"authentication",accessDenied:"authorization",paymentRequired:"entitlement",quotaExceeded:"rateLimit",rateLimited:"rateLimit",validationFailed:"invalidRequest",sdkUpdateRequired:"invalidRequest",runtimeDisposed:"invalidRequest",conversationNotFound:"notFound",petNotFound:"notFound",resourceNotFound:"notFound",conflict:"conflict",idempotencyConflict:"conflict",idempotencyInFlight:"conflict",streamTimeout:"connection",streamIncomplete:"connection",upstreamLlmTimeout:"connection",serviceUnavailable:"connection",internalError:"server",notImplemented:"server",mediaUploadFailed:"media",moderationBlocked:"policy",unknown:"unknown"});function categoryFor(e){return E[e]}function fromWire(e){let t=contractErrorFor(e);if(t)return t.normalized;let r=(e??"").trim().toUpperCase(),n=r.replace(/[^A-Z0-9]/g,"");if(n==="AUTHREJECTED")return"authRejected";if(r.startsWith("AUTH"))return"authExpired";switch(n){case"DAILYQUOTAEXCEEDED":case"QUOTAEXCEEDED":return"quotaExceeded";case"RATELIMITED":case"TOOMANYREQUESTS":case"TELEVETRATELIMITED":return"rateLimited";case"IDEMPOTENCYKEYCONFLICT":case"IDEMPOTENCYCONFLICT":return"idempotencyConflict";case"ACCESSDENIED":case"FORBIDDEN":return"accessDenied";case"IDENTITYSIGNATUREREQUIRED":return"identitySignatureRequired";case"FREECAPREACHED":return"paymentRequired";case"RUNTIMEDISPOSED":return"runtimeDisposed";case"NOTFOUND":case"CONVERSATIONNOTFOUND":return"conversationNotFound";case"PETNOTFOUND":return"petNotFound";case"TIMEOUT":case"STREAMTIMEOUT":return"streamTimeout";case"MEDIAUPLOADFAILED":case"UNRECOGNIZEDVIDEOFORMAT":case"FILETOOSMALL":return"mediaUploadFailed";case"MODERATIONBLOCKED":return"moderationBlocked";case"UPSTREAMLLMTIMEOUT":return"upstreamLlmTimeout";case"INTERNALERROR":case"INTERNALSERVERERROR":return"internalError";case"STREAMINCOMPLETE":case"CHATSTREAMINCOMPLETE":return"streamIncomplete";case"INVALIDANALYSISTYPE":case"INVALIDUPLOADPURPOSE":return"unknown";default:return"unknown"}}function fromHttpStatus(e){return e===401?"authExpired":e===403?"accessDenied":e===404?"conversationNotFound":e===409?"idempotencyConflict":e===421?"unknown":e===429?"rateLimited":e===400||e===422?"unknown":e>=500?"internalError":"unknown"}var T=/* @__PURE__ */new Set(["streamTimeout","rateLimited","internalError","upstreamLlmTimeout","streamIncomplete"]);function isAutoRetryable(e){return T.has(e)}var $=/* @__PURE__ */new Set(["serviceUnavailable","conflict","idempotencyInFlight"]);function isRetryableCode(e){return isAutoRetryable(e)||$.has(e)}var R="This feature isn't available on your account right now.",A="Something in that request was not right. Check the details and try again.",k=/* @__PURE__ */Object.freeze({authExpired:"Please sign in again to continue.",authRejected:"Please sign in again to continue.",sessionRequired:"This app needs to be updated to keep using Everfur.",accessDenied:R,paymentRequired:"This is part of a paid plan.",quotaExceeded:"You have used today's messages. This resets tomorrow.",rateLimited:"You are sending messages quickly. Try again in a few seconds.",validationFailed:A,sdkUpdateRequired:"This app needs to be updated to keep using Everfur.",conflict:"That is already running. Wait for it to finish, then try again.",idempotencyConflict:"That message was already delivered.",idempotencyInFlight:"That is still processing. Give it a moment.",conversationNotFound:"This conversation is no longer available.",petNotFound:"We could not find that pet. Please pick a pet and try again.",resourceNotFound:"We could not find that.",streamTimeout:"The response timed out. Tap retry to try again.",mediaUploadFailed:"We could not upload that photo. Please attach it again.",moderationBlocked:"This request cannot be answered here.",upstreamLlmTimeout:"The response timed out. Tap retry to try again.",internalError:"We hit a snag on our end. Please try again.",notImplemented:"That is not available yet.",serviceUnavailable:"That service is briefly unavailable. Try again shortly.",streamIncomplete:"The connection dropped mid-answer. Tap retry to continue.",identitySignatureRequired:R,runtimeDisposed:A,unknown:"Something went wrong. Please try again."}),I="This session has ended. Please sign in again.",D="linked_account_read_only";function F(e,t,r){return e==="conflict"&&r===D?R:(e==="authRejected"||e==="authExpired")&&typeof t=="string"&&t.trim().toLowerCase()==="session_revoked"?I:userFacingError(e)}function userFacingError(e){return k[e]}function O(e,t,r){Object.defineProperty(e,t,{value:r,enumerable:false,writable:false,configurable:false})}var j=/^[a-z][a-z0-9_]{0,63}$/;function makeEverfurError(e,t){let r=contractErrorFor(t?.wireCode,t?.wireEnvelope),n=e==="conflict"&&t?.reasonCode===D,a={code:e,category:categoryFor(e),retryable:t?.retryable??(n?false:isRetryableCode(e)),displayMessage:F(e,t?.wireCode,n?D:null)};t?.httpStatus!==void 0&&(a.httpStatus=t.httpStatus),t?.requestId&&(a.requestId=t.requestId),typeof t?.reasonCode=="string"&&j.test(t.reasonCode)&&(a.reasonCode=t.reasonCode);let i=t?.retryAfterSeconds;if(typeof i=="number"&&Number.isFinite(i)&&i>=0&&(a.retryAfterSeconds=Math.round(i)),r);return t?.wireMessage&&O(a,"wireMessage",t.wireMessage),t?.raw!==void 0&&t.raw!==null&&O(a,"raw",t.raw),/* @__PURE__ */Object.freeze(a)}var N="free_cap_reached";function x(e){return typeof e=="number"&&Number.isInteger(e)&&e>=0?e:null}function U(e){if(typeof e!="object"||e===null)return null;let t=e,r=t.detail,n=typeof r=="object"&&r!==null?r:t;if(n.error!==N&&n.code!==N)return null;let a=x(n.limit),i=x(n.used);if(a===null||i===null)return null;let o=n.resets_at,l=n.emergency_guidance;/* @__PURE__ */
|
|
7
7
|
return Object.freeze({limit:a,used:i,resetsAt:typeof o=="string"&&o.length>0?o:null,...typeof l=="string"&&l.trim().length>0?{emergencyGuidance:l}:{}})}function q(e,t){if(e.status!==429&&e.status!==503)return t;let r=z(e.headers.get(L),Date.now());if(r===null)return t;let n=t!==null&&typeof t=="object"&&!Array.isArray(t)?t:null;return n!==null&&P(n)?t:{...n??{},retry_after_seconds:r}}var L="retry-after";function z(e,t){if(e===null)return null;let r=e.trim();if(/^\d+$/.test(r))return Number(r);let n=Date.parse(r);return Number.isFinite(n)?Math.max(0,Math.ceil((n-t)/1e3)):null}function P(e){return[e,e.error,e.detail].some(e=>e!==null&&typeof e=="object"&&("retry_after_seconds"in e||"resets_at"in e))}var M="x-request-id";function errorFromResponse(e,t,r){let n=Y(t),a=n?fromWire(n):fromHttpStatus(e),i=V(t);return makeEverfurError(a,{httpStatus:e,...W(t)?{retryable:true}:{},...r?{requestId:r}:{},...n?{wireCode:n}:{},...B(t)?{reasonCode:B(t)}:{},...K(t)!==null?{retryAfterSeconds:K(t)}:{},...i?{wireMessage:i}:{},...t!=null?{raw:t}:{}})}function K(e){let t=e,r=t?.retry_after_seconds??t?.error?.retry_after_seconds;return typeof r=="number"&&Number.isFinite(r)&&r>=0?r:null}function networkError(e){return makeEverfurError("internalError",{retryable:true,wireMessage:Z(e)})}function requestIdOf(e){let t=e.headers.get(M);return typeof t=="string"&&t.length>0?t:null}function getGlobalFetch(){let t=globalThis.fetch;if(typeof t!="function")throw new e("missing-peer-dependency","global fetch is unavailable; provide config.transport or an injected fetch implementation");return t}function B(e){let t=e,r=t?.error?.reason_code??t?.reason_code;return typeof r=="string"&&r.length>0?r:null}function Y(e){let t=e,r=t?.error?.code??t?.code;return typeof r=="string"&&r.length>0?m(r,e):U(e)!==null?N:null}function V(e){let t=e,r=t?.error?.message??t?.message;return typeof r=="string"&&r.length>0?r:null}function W(e){let t=e;return t?.error?.retryable===true||t?.retryable===true}function Z(e){return e instanceof Error?e.message:typeof e=="string"?e:"network request failed"}var G=["sk_partner_","rk_partner_"];function Q(t,r){if(typeof t!="string"||t.length===0)throw new e("invalid-argument","partnerSecretKey is required");if(t.startsWith("pk_"))throw new e("invalid-argument",`partnerSecretKey is a publishable key (pk_...): ${r} needs your secret key, server side only`);if(!G.some(e=>t.startsWith(e)))throw new e("invalid-argument","partnerSecretKey must be an sk_partner_ secret key or an rk_partner_ restricted key")}var X=128;function assertValidUserRef(t){let r=typeof t=="string"?[...t].length:0;if(typeof t!="string"||r<1||r>X)throw new e("invalid-argument",`user_ref must be 1..${X} characters`);if(t.trim().length===0)throw new e("invalid-argument","user_ref must not be blank: the server strips surrounding whitespace before validating, so a whitespace-only value arrives empty and is rejected as required.");if(t!==t.trim())throw new e("invalid-argument","user_ref must not have leading or trailing whitespace: the server strips it, so padded and unpadded forms of the same id resolve to ONE user. Pass the exact id you want to key on.");if(t.includes("@"))throw new e("invalid-argument","user_ref must not contain '@'");if(!H(t))throw new e("invalid-argument","user_ref must be printable (no control characters)");return t}function H(e){return!J.test(e)}var J=/[\p{Cc}\p{Cf}\p{Cs}\p{Co}\p{Cn}\p{Zl}\p{Zp}]|(?!\u0020)[\p{Zs}]/u,ee="user_ref_invalid";function te(e){let t=e.raw,r=typeof t=="object"&&t!==null?t:null,n=(r!==null&&typeof r.error=="object"&&r.error!==null?r.error.code:void 0)??r?.code;return n!==ee&&e.reasonCode!==ee?e:makeEverfurError("validationFailed",{retryable:false,...e.httpStatus!==void 0?{httpStatus:e.httpStatus}:{},...e.requestId!==void 0?{requestId:e.requestId}:{},...typeof n=="string"?{wireCode:n}:{},reasonCode:ee,...e.wireMessage!==void 0?{wireMessage:e.wireMessage}:{},...t!==void 0?{raw:t}:{}})}function re(e){let t=e.raw;if(typeof t!="object"||t===null)return null;let r=t.code;return typeof r=="string"&&r.length>0?r:null}function ne(e,t){let r=re(e);if(r===null)return e;let n=t[r];return n===void 0?e:makeEverfurError(n.code,{retryable:n.retryable,...e.httpStatus!==void 0?{httpStatus:e.httpStatus}:{},...e.requestId!==void 0?{requestId:e.requestId}:{},wireCode:r,reasonCode:r,...e.wireMessage!==void 0?{wireMessage:e.wireMessage}:{},raw:e.raw})}function ae(e,t){let r=ne(e,t);if(r!==e||re(e)!==null)return r;let n=e.reasonCode;if(typeof n!="string")return e;let a=t[n];return a===void 0?e:makeEverfurError(a.code,{retryable:a.retryable,...e.httpStatus!==void 0?{httpStatus:e.httpStatus}:{},...e.requestId!==void 0?{requestId:e.requestId}:{},wireCode:n,reasonCode:n,...e.wireMessage!==void 0?{wireMessage:e.wireMessage}:{},raw:e.raw})}var ie=64;function oe(t){if(t!=null){if(typeof t!="string"||t.length===0||t.length>ie||/\s/.test(t))throw new e("invalid-argument",`timezone must be an IANA zone name such as 'America/Chicago' (at most ${ie} characters)`);return t}}function le(e){for(let t=0;t<e.length;t+=1){let r=e.charCodeAt(t);if(r>=55296&&r<=56319){let r=e.charCodeAt(t+1);if(!(r>=56320&&r<=57343))return true;t+=1}else if(r>=56320&&r<=57343)return true}return false}function se(e){return[...e].length}var ue=/* @__PURE__ */Object.freeze({dog:"dog",canine:"dog",k9:"dog",puppy:"dog",cat:"cat",feline:"cat",kitten:"cat"});function canonicalPetSpecies(e){if(typeof e!="string")return null;let t=e.trim().toLowerCase();return Object.prototype.hasOwnProperty.call(ue,t)?ue[t]:null}var de=50,pe=128,ce=120,fe=120,ve=2e3,_e=120,he=80,me=/* @__PURE__ */new Set(["male","female","unknown"]),ye=/* @__PURE__ */new Set(["day","month","year"]),be=/* @__PURE__ */new Set(["low","medium","high","athletic"]),ge=/* @__PURE__ */new Set(["indoor","outdoor","both"]),we=/* @__PURE__ */new Set(["mild","moderate","severe"]),Se=/^(\d{4})-(\d{2})-(\d{2})$/,Ce=[["sex","sex"],["spayedNeutered","spayed_neutered"],["birthDate","birth_date"],["birthDatePrecision","birth_date_precision"],["activityLevel","activity_level"],["indoorOutdoor","indoor_outdoor"],["foodBrand","food_brand"],["foodType","food_type"],["microchipId","microchip_id"]],Ee=[["allergies","allergies"],["medications","medications"],["supplements","supplements"],["conditions","conditions"]];/* @__PURE__ */Object.freeze([...Ce,...Ee].map(([e])=>e));function Te(e){let t=Se.exec(e);if(t===null)return false;let[r,n,a]=[Number(t[1]),Number(t[2]),Number(t[3])],i=new Date(Date.UTC(r,n-1,a));return i.getUTCFullYear()===r&&i.getUTCMonth()===n-1&&i.getUTCDate()===a}var $e=e=>(t,r)=>typeof r=="string"&&e.has(r)?null:`${t} must be one of ${[...e].join(", ")}`,Re=(e,t)=>typeof t=="boolean"?null:`${e} must be true or false`,Ae=(e,t)=>typeof t=="string"&&Te(t)?null:`${e} must be a real date written YYYY-MM-DD`,ke=(e,t={})=>(r,n)=>{if(typeof n!="string")return`${r} must be a string`;if(le(n))return`${r} contains an unpaired surrogate and cannot be encoded`;let a=t.trimmed?n.trim():n;if(t.required&&a.length===0)return`${r} is required and must not be blank`;let i=se(a);return i<=e?null:`${r} is ${i} characters; the server accepts at most ${e}`},Ie={sex:$e(me),spayedNeutered:Re,birthDate:Ae,birthDatePrecision:$e(ye),activityLevel:$e(be),indoorOutdoor:$e(ge),foodBrand:ke(_e),foodType:ke(_e),microchipId:ke(he)},De=["ref","ref",false,ke(pe,{required:true,trimmed:true})],Fe=["notes","notes",false,ke(ve,{trimmed:true})],Oe=[De,["name","name",true,ke(ce,{required:true,trimmed:true})],["dose","dose",false,ke(fe,{trimmed:true})],["frequency","frequency",false,ke(fe,{trimmed:true})],["startDate","start_date",false,Ae],["endDate","end_date",false,Ae],Fe],je={allergies:[De,["allergen","allergen",true,ke(ce,{required:true,trimmed:true})],["severity","severity",false,$e(we)],Fe],medications:Oe,supplements:Oe,conditions:[De,["conditionName","condition_name",true,ke(ce,{required:true,trimmed:true})],["diagnosedDate","diagnosed_date",false,Ae],Fe]};function Ne(e,t,r){let n=`${e}[${t}]`;if(typeof r!="object"||r===null||Array.isArray(r))return{error:`${n} must be an object`};let a=r,i={};for(let[t,r,o,l]of je[e]){let e=a[t];if(e==null){if(o)return{error:`${n}.${t} is required`};e===null&&(i[r]=null);continue}let s=l(`${n}.${t}`,e);if(s!==null)return{error:s};i[r]=e}let o=i.start_date,l=i.end_date;return typeof o=="string"&&typeof l=="string"&&l<o?{error:`${n}.endDate must not be before startDate`}:{item:i}}function xe(e,t){if(!Array.isArray(t))return{error:`${e} must be an array (send [] to clear it)`};if(t.length>de)return{error:`${e} has ${t.length} items; the server accepts at most ${de}`};let r=[],n=/* @__PURE__ */new Set;for(let a=0;a<t.length;a+=1){let i=Ne(e,a,t[a]);if("error"in i)return i;let o=i.item.ref;if(typeof o=="string"){let t=o.trim();if(n.has(t))return{error:`${e}: ref ${JSON.stringify(t)} is used twice; a ref names one item`};n.add(t)}r.push(i.item)}return{items:r}}function Ue(e,t){let r=e,n={};for(let[e,t]of Ce){let a=r[e];if(a!==void 0){if(a!==null){let t=Ie[e](e,a);if(t!==null)return{error:t}}n[t]=a}}let a=r.birthDate!==void 0,i=r.birthDatePrecision!==void 0;if(a!==i||a&&r.birthDate===null!=(r.birthDatePrecision===null))return{error:"birthDate and birthDatePrecision must be sent together, both set or both null"};for(let[e,t]of Ee){let a=r[e];if(a===void 0)continue;let i=xe(e,a);if("error"in i)return i;n[t]=i.items}return Object.keys(n).length>0&&t!==void 0&&canonicalPetSpecies(t)===null?{error:"health fields need a pet Everfur reads as a dog or a cat (dog, canine, k9, puppy, cat, feline, kitten)"}:{body:n}}var qe=e=>typeof e=="string"?e:null,Le=(e,t)=>typeof t=="string"&&e.has(t)?t:null,ze=e=>typeof e=="boolean"?e:null;function Pe(e,t){return Array.isArray(e)?/* @__PURE__ */Object.freeze(e.flatMap(e=>{if(typeof e!="object"||e===null||Array.isArray(e))return[];let r=t(e);return r===null?[]:[r]})):/* @__PURE__ */Object.freeze([])}function Me(e){let t=qe(e.name);return t===null||t.length===0?null:/* @__PURE__ */Object.freeze({ref:qe(e.ref),name:t,dose:qe(e.dose),frequency:qe(e.frequency),startDate:qe(e.start_date),endDate:qe(e.end_date),notes:qe(e.notes)})}function Ke(e){let t=e.profile_version;/* @__PURE__ */
|
package/dist/server/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*! @everfur/sdk. Copyright (c) 2026 Strand Health Inc. dba Everfur. All rights reserved. Use is subject to the Everfur SDK License: https://docs.everfur.com/license */
|
|
2
2
|
function ok(e,t){/* @__PURE__ */
|
|
3
3
|
return Object.freeze({ok:true,value:e})}function err(e){/* @__PURE__ */
|
|
4
|
-
return Object.freeze({ok:false,error:e})}var e=class _EverfurConfigError extends Error{constructor(e,t){super(t),this.name="EverfurConfigError",this.kind=e,Object.setPrototypeOf(this,_EverfurConfigError.prototype)}};var t=/^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^/?#]*)/;var r="1.5.
|
|
4
|
+
return Object.freeze({ok:false,error:e})}var e=class _EverfurConfigError extends Error{constructor(e,t){super(t),this.name="EverfurConfigError",this.kind=e,Object.setPrototypeOf(this,_EverfurConfigError.prototype)}};var t=/^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^/?#]*)/;var r="1.5.2";var n="2026-09-19",a="EVERFUR_API_BASE_URL";function i(e,t){/* @__PURE__ */
|
|
5
5
|
return Object.freeze({ok:false,failure:/* @__PURE__ */Object.freeze({reason:e,message:t})})}function tryResolveApiBaseUrl(e){let t=e?.trim(),r=t&&t.length>0?t:c(a);return r?d(r):i("missing-api-base-url",`apiBaseUrl is required: pass config.apiBaseUrl or set ${a}. The SDK never ships a hardcoded host.`)}function resolveApiBaseUrl(t){let r=tryResolveApiBaseUrl(t);if(!r.ok)throw new e("invalid-argument",r.failure.message);return r.value}function o(e){return e.slice(e.lastIndexOf("@")+1).replace(/:\d+$/,"").toLowerCase()}function l(e){return e.length===0||e.includes("@")?false:e.startsWith("[")&&e.endsWith("]")?true:!e.includes(":")}function s(e,t){let r=e.indexOf("://");return r<0||e.slice(r+3).includes("@")?false:l(t)}function u(e,t){return`${e}://${t}`}function d(e){let r=e.trim(),n=t.exec(r);if(n===null||n[2]===void 0||n[2].length===0)return i("malformed-api-base-url","apiBaseUrl is not a valid absolute URL");let a=(n[1]??"").toLowerCase(),l=o(n[2]);if(l.length===0)return i("malformed-api-base-url","apiBaseUrl is not a valid absolute URL");let d=s(r,l)?`: ${u(a,l)}`:"";if(a!=="https"){if(!(a==="http"&&p(l)))return a==="http"?i("insecure-api-base-url",`apiBaseUrl must use https (cleartext http is only allowed for localhost)${d}`):i("unsupported-api-base-url-scheme",`apiBaseUrl must be http(s)${d}`)}let c=r.endsWith("/")?r.slice(0,-1):r;/* @__PURE__ */
|
|
6
6
|
return Object.freeze({ok:true,value:c})}function p(e){let t=e.toLowerCase();return t==="localhost"||t==="127.0.0.1"||t==="[::1]"||t==="::1"}function c(e){let t=globalThis.process?.env?.[e];return typeof t=="string"&&t.trim().length>0?t.trim():void 0}var f="server";function v(e){return{"X-Everfur-SDK-Version":r,"X-Everfur-SDK-Platform":f,"X-Everfur-Contract":e}}var _="DAILY_QUOTA_EXCEEDED",h=/* @__PURE__ */new Set(["THROTTLINGEXCEPTION","RATELIMITED","TOOMANYREQUESTS"]);function m(e,t){if(!h.has(e.toUpperCase().replace(/[^A-Z0-9]/g,"")))return e;let r=t,n=r?.daily_limit??r?.error?.daily_limit;return typeof n=="number"&&Number.isFinite(n)?_:e}var y=[{wireCode:"AccessDeniedException",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"AuthorizationException",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"ConflictException",envelope:"http_envelope",httpStatus:409,retryable:true},{wireCode:"DAILY_QUOTA_EXCEEDED",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"FILE_TOO_LARGE",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"IDEMPOTENCY_KEY_IN_FLIGHT",envelope:"http_envelope",httpStatus:409,retryable:true},{wireCode:"IDEMPOTENCY_KEY_REUSED_DIFFERENT_REQUEST",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"INVALID_CONTENT_TYPE",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"InternalFailureException",envelope:"http_envelope",httpStatus:500,retryable:true},{wireCode:"MethodNotAllowedException",envelope:"http_envelope",httpStatus:405,retryable:false},{wireCode:"NotImplementedException",envelope:"http_envelope",httpStatus:501,retryable:false},{wireCode:"PaymentRequiredException",envelope:"http_envelope",httpStatus:402,retryable:false},{wireCode:"ResourceNotFoundException",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"ServiceUnavailableException",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"TIER_UPGRADE_REQUIRED",envelope:"http_envelope",httpStatus:402,retryable:false},{wireCode:"ThrottlingException",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"ValidationException",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"accessDenied",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"access_denied",envelope:"oauth_error",httpStatus:302,retryable:false},{wireCode:"anchor_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"anchor_ref_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"anonTokenInvalid",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"attachment_unreadable",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"authExpired",envelope:"http_envelope",httpStatus:401,retryable:true},{wireCode:"authRejected",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"before_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"bundle_mismatch",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"bundle_not_uploaded",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"bundles_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"catalog_empty_refused",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"catalog_shrink_refused",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"consent_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"consent_required",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"consent_scope_wrong_route",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"device_cipher_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"email_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"endpoint_not_allowed",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"environment_mismatch",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"event_cursor_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_filter_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_id_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"event_payload_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_type_not_available",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"event_type_unknown",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"idempotency_key_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"idempotency_key_required",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"idempotency_key_reused",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"inbox_cursor_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"insufficientCapability",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"insufficient_scope",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"internal_error",envelope:"sse_frame",httpStatus:200,retryable:false},{wireCode:"invalidRequest",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"invalid_client",envelope:"oauth_error",httpStatus:401,retryable:false},{wireCode:"invalid_client_metadata",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_grant",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_redirect_uri",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_request",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_scope",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"invalid_target",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"item_id_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"linked_account_read_only",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"mcp_connection_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"mcp_request_conflict",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"mcp_request_gone",envelope:"http_envelope",httpStatus:410,retryable:false},{wireCode:"mcp_request_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"not_found",envelope:"sse_frame",httpStatus:200,retryable:false},{wireCode:"not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"open_url_not_allowed",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"partner_visit_link_conflict",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"partner_visit_owner_only",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"partner_visit_pet_already_mapped",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"payload_too_large",envelope:"http_envelope",httpStatus:413,retryable:false},{wireCode:"petRefInUse",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"pet_health_list_removals_unconfirmed",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"pet_health_species_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"pet_not_registered",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"provider_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"rateLimited",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"read_target_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"record_species_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"record_subject_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"record_upload_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"records_consent_required",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"restricted_key",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"sandbox_only",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"session_required",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"session_revoked",envelope:"http_envelope",httpStatus:401,retryable:false},{wireCode:"share_limit_reached",envelope:"http_envelope",httpStatus:429,retryable:false},{wireCode:"slow_down",envelope:"oauth_error",httpStatus:429,retryable:true},{wireCode:"species_unsupported",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"subscription_keys_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"tenant_filter_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"tenant_has_no_capabilities",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"tenant_resource_not_found",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"tenant_surface_not_enabled",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"ticket_not_resolved",envelope:"http_envelope",httpStatus:409,retryable:false},{wireCode:"tickets_disabled",envelope:"http_envelope",httpStatus:404,retryable:false},{wireCode:"timeout",envelope:"sse_frame",httpStatus:200,retryable:true},{wireCode:"timezone_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"token_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"unavailable",envelope:"sse_frame",httpStatus:200,retryable:true},{wireCode:"unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"unrestrictedKeyRequired",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"unsupported_grant_type",envelope:"oauth_error",httpStatus:400,retryable:false},{wireCode:"unsupported_response_type",envelope:"oauth_error",httpStatus:302,retryable:false},{wireCode:"user_ref_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"verify_mint_rate_limited",envelope:"http_envelope",httpStatus:429,retryable:true},{wireCode:"verify_mint_refused",envelope:"http_envelope",httpStatus:403,retryable:false},{wireCode:"verify_mint_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"verify_user_ref_invalid",envelope:"http_envelope",httpStatus:422,retryable:false},{wireCode:"web_push_unavailable",envelope:"http_envelope",httpStatus:503,retryable:true},{wireCode:"webhook_endpoint_update_empty",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"webhook_endpoint_update_invalid",envelope:"http_envelope",httpStatus:400,retryable:false},{wireCode:"webhook_url_rejected",envelope:"http_envelope",httpStatus:400,retryable:false}],b=/* @__PURE__ */Object.freeze(y.map(e=>/* @__PURE__ */Object.freeze(e)));/* @__PURE__ */Object.freeze(b.map(e=>e.wireCode));var g=/* @__PURE__ */Object.freeze({ValidationException:"validationFailed",AuthorizationException:"authRejected",PaymentRequiredException:"paymentRequired",AccessDeniedException:"accessDenied",ResourceNotFoundException:"resourceNotFound",ConflictException:"conflict",ThrottlingException:"rateLimited",InternalFailureException:"internalError",NotImplementedException:"notImplemented",ServiceUnavailableException:"serviceUnavailable",MethodNotAllowedException:"validationFailed",authExpired:"authExpired",unavailable:"serviceUnavailable",session_required:"sessionRequired",session_revoked:"authExpired",anonTokenInvalid:"authRejected",accessDenied:"accessDenied",invalidRequest:"sdkUpdateRequired",authRejected:"authRejected",rateLimited:"rateLimited",insufficientCapability:"accessDenied",unrestrictedKeyRequired:"accessDenied",user_ref_invalid:"validationFailed",event_cursor_invalid:"validationFailed",event_filter_invalid:"validationFailed",event_payload_invalid:"validationFailed",event_type_unknown:"validationFailed",idempotency_key_invalid:"validationFailed",idempotency_key_required:"validationFailed",idempotency_key_reused:"idempotencyConflict",payload_too_large:"validationFailed",webhook_url_rejected:"validationFailed",webhook_endpoint_update_empty:"validationFailed",webhook_endpoint_update_invalid:"validationFailed",event_type_not_available:"conflict",record_subject_not_found:"resourceNotFound",records_consent_required:"conflict",record_species_unsupported:"validationFailed",record_upload_invalid:"validationFailed",FILE_TOO_LARGE:"validationFailed",INVALID_CONTENT_TYPE:"validationFailed",attachment_unreadable:"validationFailed",provider_unsupported:"validationFailed",token_invalid:"validationFailed",device_cipher_unavailable:"serviceUnavailable",email_invalid:"validationFailed",consent_required:"validationFailed",consent_invalid:"validationFailed",consent_scope_wrong_route:"validationFailed",IDEMPOTENCY_KEY_IN_FLIGHT:"idempotencyInFlight",IDEMPOTENCY_KEY_REUSED_DIFFERENT_REQUEST:"idempotencyConflict",DAILY_QUOTA_EXCEEDED:"quotaExceeded",TIER_UPGRADE_REQUIRED:"paymentRequired",not_found:"conversationNotFound",timeout:"streamTimeout",internal_error:"internalError",invalid_request:"validationFailed",invalid_client:"authRejected",invalid_grant:"authRejected",unsupported_grant_type:"validationFailed",invalid_scope:"validationFailed",invalid_target:"validationFailed",invalid_redirect_uri:"validationFailed",invalid_client_metadata:"validationFailed",unsupported_response_type:"validationFailed",access_denied:"accessDenied",slow_down:"rateLimited",mcp_request_not_found:"resourceNotFound",mcp_request_gone:"resourceNotFound",mcp_connection_not_found:"resourceNotFound",mcp_request_conflict:"conflict",sandbox_only:"accessDenied",tenant_has_no_capabilities:"conflict",verify_mint_refused:"accessDenied",verify_mint_rate_limited:"rateLimited",verify_mint_unavailable:"serviceUnavailable",verify_user_ref_invalid:"validationFailed",insufficient_scope:"accessDenied",tenant_filter_invalid:"validationFailed",tenant_resource_not_found:"resourceNotFound",tenant_surface_not_enabled:"conflict",pet_health_species_unsupported:"validationFailed",pet_health_list_removals_unconfirmed:"validationFailed",petRefInUse:"conflict",share_limit_reached:"conflict",pet_not_registered:"resourceNotFound",species_unsupported:"validationFailed",partner_visit_owner_only:"accessDenied",partner_visit_link_conflict:"conflict",partner_visit_pet_already_mapped:"conflict",linked_account_read_only:"conflict",catalog_empty_refused:"conflict",catalog_shrink_refused:"conflict",endpoint_not_allowed:"validationFailed",event_id_invalid:"validationFailed",inbox_cursor_invalid:"validationFailed",item_id_invalid:"validationFailed",open_url_not_allowed:"validationFailed",read_target_invalid:"validationFailed",subscription_keys_invalid:"validationFailed",web_push_unavailable:"serviceUnavailable",anchor_not_found:"resourceNotFound",anchor_ref_invalid:"validationFailed",before_invalid:"validationFailed",bundle_mismatch:"validationFailed",bundle_not_uploaded:"validationFailed",bundles_unavailable:"serviceUnavailable",environment_mismatch:"validationFailed",restricted_key:"accessDenied",ticket_not_resolved:"conflict",tickets_disabled:"resourceNotFound",timezone_invalid:"validationFailed"}),w=/* @__PURE__ */Object.freeze(b.map(e=>/* @__PURE__ */Object.freeze({wireCode:e.wireCode,envelope:e.envelope,retryable:e.retryable,normalized:g[e.wireCode]}))),S=new Map(w.map(e=>[e.envelope+e.wireCode.toUpperCase(),e])),C=/* @__PURE__ */Object.freeze(["http_envelope",...[...new Set(w.map(e=>e.envelope))].filter(e=>e!=="http_envelope").sort()]);function contractErrorFor(e,t){if(typeof e!="string")return;let r=e.trim().toUpperCase();if(r.length!==0)for(let e of[t??"http_envelope",...C]){let t=S.get(e+r);if(t)return t}}var E=/* @__PURE__ */Object.freeze({authExpired:"authentication",authRejected:"authentication",sessionRequired:"authentication",identitySignatureRequired:"authentication",accessDenied:"authorization",paymentRequired:"entitlement",quotaExceeded:"rateLimit",rateLimited:"rateLimit",validationFailed:"invalidRequest",sdkUpdateRequired:"invalidRequest",runtimeDisposed:"invalidRequest",conversationNotFound:"notFound",petNotFound:"notFound",resourceNotFound:"notFound",conflict:"conflict",idempotencyConflict:"conflict",idempotencyInFlight:"conflict",streamTimeout:"connection",streamIncomplete:"connection",upstreamLlmTimeout:"connection",serviceUnavailable:"connection",internalError:"server",notImplemented:"server",mediaUploadFailed:"media",moderationBlocked:"policy",unknown:"unknown"});function categoryFor(e){return E[e]}function fromWire(e){let t=contractErrorFor(e);if(t)return t.normalized;let r=(e??"").trim().toUpperCase(),n=r.replace(/[^A-Z0-9]/g,"");if(n==="AUTHREJECTED")return"authRejected";if(r.startsWith("AUTH"))return"authExpired";switch(n){case"DAILYQUOTAEXCEEDED":case"QUOTAEXCEEDED":return"quotaExceeded";case"RATELIMITED":case"TOOMANYREQUESTS":case"TELEVETRATELIMITED":return"rateLimited";case"IDEMPOTENCYKEYCONFLICT":case"IDEMPOTENCYCONFLICT":return"idempotencyConflict";case"ACCESSDENIED":case"FORBIDDEN":return"accessDenied";case"IDENTITYSIGNATUREREQUIRED":return"identitySignatureRequired";case"FREECAPREACHED":return"paymentRequired";case"RUNTIMEDISPOSED":return"runtimeDisposed";case"NOTFOUND":case"CONVERSATIONNOTFOUND":return"conversationNotFound";case"PETNOTFOUND":return"petNotFound";case"TIMEOUT":case"STREAMTIMEOUT":return"streamTimeout";case"MEDIAUPLOADFAILED":case"UNRECOGNIZEDVIDEOFORMAT":case"FILETOOSMALL":return"mediaUploadFailed";case"MODERATIONBLOCKED":return"moderationBlocked";case"UPSTREAMLLMTIMEOUT":return"upstreamLlmTimeout";case"INTERNALERROR":case"INTERNALSERVERERROR":return"internalError";case"STREAMINCOMPLETE":case"CHATSTREAMINCOMPLETE":return"streamIncomplete";case"INVALIDANALYSISTYPE":case"INVALIDUPLOADPURPOSE":return"unknown";default:return"unknown"}}function fromHttpStatus(e){return e===401?"authExpired":e===403?"accessDenied":e===404?"conversationNotFound":e===409?"idempotencyConflict":e===421?"unknown":e===429?"rateLimited":e===400||e===422?"unknown":e>=500?"internalError":"unknown"}var $=/* @__PURE__ */new Set(["streamTimeout","rateLimited","internalError","upstreamLlmTimeout","streamIncomplete"]);function isAutoRetryable(e){return $.has(e)}var T=/* @__PURE__ */new Set(["serviceUnavailable","conflict","idempotencyInFlight"]);function isRetryableCode(e){return isAutoRetryable(e)||T.has(e)}var R="This feature isn't available on your account right now.",A="Something in that request was not right. Check the details and try again.",I=/* @__PURE__ */Object.freeze({authExpired:"Please sign in again to continue.",authRejected:"Please sign in again to continue.",sessionRequired:"This app needs to be updated to keep using Everfur.",accessDenied:R,paymentRequired:"This is part of a paid plan.",quotaExceeded:"You have used today's messages. This resets tomorrow.",rateLimited:"You are sending messages quickly. Try again in a few seconds.",validationFailed:A,sdkUpdateRequired:"This app needs to be updated to keep using Everfur.",conflict:"That is already running. Wait for it to finish, then try again.",idempotencyConflict:"That message was already delivered.",idempotencyInFlight:"That is still processing. Give it a moment.",conversationNotFound:"This conversation is no longer available.",petNotFound:"We could not find that pet. Please pick a pet and try again.",resourceNotFound:"We could not find that.",streamTimeout:"The response timed out. Tap retry to try again.",mediaUploadFailed:"We could not upload that photo. Please attach it again.",moderationBlocked:"This request cannot be answered here.",upstreamLlmTimeout:"The response timed out. Tap retry to try again.",internalError:"We hit a snag on our end. Please try again.",notImplemented:"That is not available yet.",serviceUnavailable:"That service is briefly unavailable. Try again shortly.",streamIncomplete:"The connection dropped mid-answer. Tap retry to continue.",identitySignatureRequired:R,runtimeDisposed:A,unknown:"Something went wrong. Please try again."}),k="This session has ended. Please sign in again.",D="linked_account_read_only";function F(e,t,r){return e==="conflict"&&r===D?R:(e==="authRejected"||e==="authExpired")&&typeof t=="string"&&t.trim().toLowerCase()==="session_revoked"?k:userFacingError(e)}function userFacingError(e){return I[e]}function O(e,t,r){Object.defineProperty(e,t,{value:r,enumerable:false,writable:false,configurable:false})}var j=/^[a-z][a-z0-9_]{0,63}$/;function makeEverfurError(e,t){let r=contractErrorFor(t?.wireCode,t?.wireEnvelope),n=e==="conflict"&&t?.reasonCode===D,a={code:e,category:categoryFor(e),retryable:t?.retryable??(n?false:isRetryableCode(e)),displayMessage:F(e,t?.wireCode,n?D:null)};t?.httpStatus!==void 0&&(a.httpStatus=t.httpStatus),t?.requestId&&(a.requestId=t.requestId),typeof t?.reasonCode=="string"&&j.test(t.reasonCode)&&(a.reasonCode=t.reasonCode);let i=t?.retryAfterSeconds;if(typeof i=="number"&&Number.isFinite(i)&&i>=0&&(a.retryAfterSeconds=Math.round(i)),r);return t?.wireMessage&&O(a,"wireMessage",t.wireMessage),t?.raw!==void 0&&t.raw!==null&&O(a,"raw",t.raw),/* @__PURE__ */Object.freeze(a)}var N="free_cap_reached";function x(e){return typeof e=="number"&&Number.isInteger(e)&&e>=0?e:null}function U(e){if(typeof e!="object"||e===null)return null;let t=e,r=t.detail,n=typeof r=="object"&&r!==null?r:t;if(n.error!==N&&n.code!==N)return null;let a=x(n.limit),i=x(n.used);if(a===null||i===null)return null;let o=n.resets_at,l=n.emergency_guidance;/* @__PURE__ */
|
|
7
7
|
return Object.freeze({limit:a,used:i,resetsAt:typeof o=="string"&&o.length>0?o:null,...typeof l=="string"&&l.trim().length>0?{emergencyGuidance:l}:{}})}function q(e,t){if(e.status!==429&&e.status!==503)return t;let r=z(e.headers.get(L),Date.now());if(r===null)return t;let n=t!==null&&typeof t=="object"&&!Array.isArray(t)?t:null;return n!==null&&P(n)?t:{...n??{},retry_after_seconds:r}}var L="retry-after";function z(e,t){if(e===null)return null;let r=e.trim();if(/^\d+$/.test(r))return Number(r);let n=Date.parse(r);return Number.isFinite(n)?Math.max(0,Math.ceil((n-t)/1e3)):null}function P(e){return[e,e.error,e.detail].some(e=>e!==null&&typeof e=="object"&&("retry_after_seconds"in e||"resets_at"in e))}var M="x-request-id";function errorFromResponse(e,t,r){let n=Y(t),a=n?fromWire(n):fromHttpStatus(e),i=V(t);return makeEverfurError(a,{httpStatus:e,...W(t)?{retryable:true}:{},...r?{requestId:r}:{},...n?{wireCode:n}:{},...B(t)?{reasonCode:B(t)}:{},...K(t)!==null?{retryAfterSeconds:K(t)}:{},...i?{wireMessage:i}:{},...t!=null?{raw:t}:{}})}function K(e){let t=e,r=t?.retry_after_seconds??t?.error?.retry_after_seconds;return typeof r=="number"&&Number.isFinite(r)&&r>=0?r:null}function networkError(e){return makeEverfurError("internalError",{retryable:true,wireMessage:Z(e)})}function requestIdOf(e){let t=e.headers.get(M);return typeof t=="string"&&t.length>0?t:null}function getGlobalFetch(){let t=globalThis.fetch;if(typeof t!="function")throw new e("missing-peer-dependency","global fetch is unavailable; provide config.transport or an injected fetch implementation");return t}function B(e){let t=e,r=t?.error?.reason_code??t?.reason_code;return typeof r=="string"&&r.length>0?r:null}function Y(e){let t=e,r=t?.error?.code??t?.code;return typeof r=="string"&&r.length>0?m(r,e):U(e)!==null?N:null}function V(e){let t=e,r=t?.error?.message??t?.message;return typeof r=="string"&&r.length>0?r:null}function W(e){let t=e;return t?.error?.retryable===true||t?.retryable===true}function Z(e){return e instanceof Error?e.message:typeof e=="string"?e:"network request failed"}var G=["sk_partner_","rk_partner_"];function Q(t,r){if(typeof t!="string"||t.length===0)throw new e("invalid-argument","partnerSecretKey is required");if(t.startsWith("pk_"))throw new e("invalid-argument",`partnerSecretKey is a publishable key (pk_...): ${r} needs your secret key, server side only`);if(!G.some(e=>t.startsWith(e)))throw new e("invalid-argument","partnerSecretKey must be an sk_partner_ secret key or an rk_partner_ restricted key")}var X=128;function assertValidUserRef(t){let r=typeof t=="string"?[...t].length:0;if(typeof t!="string"||r<1||r>X)throw new e("invalid-argument",`user_ref must be 1..${X} characters`);if(t.trim().length===0)throw new e("invalid-argument","user_ref must not be blank: the server strips surrounding whitespace before validating, so a whitespace-only value arrives empty and is rejected as required.");if(t!==t.trim())throw new e("invalid-argument","user_ref must not have leading or trailing whitespace: the server strips it, so padded and unpadded forms of the same id resolve to ONE user. Pass the exact id you want to key on.");if(t.includes("@"))throw new e("invalid-argument","user_ref must not contain '@'");if(!H(t))throw new e("invalid-argument","user_ref must be printable (no control characters)");return t}function H(e){return!J.test(e)}var J=/[\p{Cc}\p{Cf}\p{Cs}\p{Co}\p{Cn}\p{Zl}\p{Zp}]|(?!\u0020)[\p{Zs}]/u,ee="user_ref_invalid";function te(e){let t=e.raw,r=typeof t=="object"&&t!==null?t:null,n=(r!==null&&typeof r.error=="object"&&r.error!==null?r.error.code:void 0)??r?.code;return n!==ee&&e.reasonCode!==ee?e:makeEverfurError("validationFailed",{retryable:false,...e.httpStatus!==void 0?{httpStatus:e.httpStatus}:{},...e.requestId!==void 0?{requestId:e.requestId}:{},...typeof n=="string"?{wireCode:n}:{},reasonCode:ee,...e.wireMessage!==void 0?{wireMessage:e.wireMessage}:{},...t!==void 0?{raw:t}:{}})}function re(e){let t=e.raw;if(typeof t!="object"||t===null)return null;let r=t.code;return typeof r=="string"&&r.length>0?r:null}function ne(e,t){let r=re(e);if(r===null)return e;let n=t[r];return n===void 0?e:makeEverfurError(n.code,{retryable:n.retryable,...e.httpStatus!==void 0?{httpStatus:e.httpStatus}:{},...e.requestId!==void 0?{requestId:e.requestId}:{},wireCode:r,reasonCode:r,...e.wireMessage!==void 0?{wireMessage:e.wireMessage}:{},raw:e.raw})}function ae(e,t){let r=ne(e,t);if(r!==e||re(e)!==null)return r;let n=e.reasonCode;if(typeof n!="string")return e;let a=t[n];return a===void 0?e:makeEverfurError(a.code,{retryable:a.retryable,...e.httpStatus!==void 0?{httpStatus:e.httpStatus}:{},...e.requestId!==void 0?{requestId:e.requestId}:{},wireCode:n,reasonCode:n,...e.wireMessage!==void 0?{wireMessage:e.wireMessage}:{},raw:e.raw})}var ie=64;function oe(t){if(t!=null){if(typeof t!="string"||t.length===0||t.length>ie||/\s/.test(t))throw new e("invalid-argument",`timezone must be an IANA zone name such as 'America/Chicago' (at most ${ie} characters)`);return t}}function le(e){for(let t=0;t<e.length;t+=1){let r=e.charCodeAt(t);if(r>=55296&&r<=56319){let r=e.charCodeAt(t+1);if(!(r>=56320&&r<=57343))return true;t+=1}else if(r>=56320&&r<=57343)return true}return false}function se(e){return[...e].length}var ue=/* @__PURE__ */Object.freeze({dog:"dog",canine:"dog",k9:"dog",puppy:"dog",cat:"cat",feline:"cat",kitten:"cat"});function canonicalPetSpecies(e){if(typeof e!="string")return null;let t=e.trim().toLowerCase();return Object.prototype.hasOwnProperty.call(ue,t)?ue[t]:null}var de=50,pe=128,ce=120,fe=120,ve=2e3,_e=120,he=80,me=/* @__PURE__ */new Set(["male","female","unknown"]),ye=/* @__PURE__ */new Set(["day","month","year"]),be=/* @__PURE__ */new Set(["low","medium","high","athletic"]),ge=/* @__PURE__ */new Set(["indoor","outdoor","both"]),we=/* @__PURE__ */new Set(["mild","moderate","severe"]),Se=/^(\d{4})-(\d{2})-(\d{2})$/,Ce=[["sex","sex"],["spayedNeutered","spayed_neutered"],["birthDate","birth_date"],["birthDatePrecision","birth_date_precision"],["activityLevel","activity_level"],["indoorOutdoor","indoor_outdoor"],["foodBrand","food_brand"],["foodType","food_type"],["microchipId","microchip_id"]],Ee=[["allergies","allergies"],["medications","medications"],["supplements","supplements"],["conditions","conditions"]];/* @__PURE__ */Object.freeze([...Ce,...Ee].map(([e])=>e));function $e(e){let t=Se.exec(e);if(t===null)return false;let[r,n,a]=[Number(t[1]),Number(t[2]),Number(t[3])],i=new Date(Date.UTC(r,n-1,a));return i.getUTCFullYear()===r&&i.getUTCMonth()===n-1&&i.getUTCDate()===a}var Te=e=>(t,r)=>typeof r=="string"&&e.has(r)?null:`${t} must be one of ${[...e].join(", ")}`,Re=(e,t)=>typeof t=="boolean"?null:`${e} must be true or false`,Ae=(e,t)=>typeof t=="string"&&$e(t)?null:`${e} must be a real date written YYYY-MM-DD`,Ie=(e,t={})=>(r,n)=>{if(typeof n!="string")return`${r} must be a string`;if(le(n))return`${r} contains an unpaired surrogate and cannot be encoded`;let a=t.trimmed?n.trim():n;if(t.required&&a.length===0)return`${r} is required and must not be blank`;let i=se(a);return i<=e?null:`${r} is ${i} characters; the server accepts at most ${e}`},ke={sex:Te(me),spayedNeutered:Re,birthDate:Ae,birthDatePrecision:Te(ye),activityLevel:Te(be),indoorOutdoor:Te(ge),foodBrand:Ie(_e),foodType:Ie(_e),microchipId:Ie(he)},De=["ref","ref",false,Ie(pe,{required:true,trimmed:true})],Fe=["notes","notes",false,Ie(ve,{trimmed:true})],Oe=[De,["name","name",true,Ie(ce,{required:true,trimmed:true})],["dose","dose",false,Ie(fe,{trimmed:true})],["frequency","frequency",false,Ie(fe,{trimmed:true})],["startDate","start_date",false,Ae],["endDate","end_date",false,Ae],Fe],je={allergies:[De,["allergen","allergen",true,Ie(ce,{required:true,trimmed:true})],["severity","severity",false,Te(we)],Fe],medications:Oe,supplements:Oe,conditions:[De,["conditionName","condition_name",true,Ie(ce,{required:true,trimmed:true})],["diagnosedDate","diagnosed_date",false,Ae],Fe]};function Ne(e,t,r){let n=`${e}[${t}]`;if(typeof r!="object"||r===null||Array.isArray(r))return{error:`${n} must be an object`};let a=r,i={};for(let[t,r,o,l]of je[e]){let e=a[t];if(e==null){if(o)return{error:`${n}.${t} is required`};e===null&&(i[r]=null);continue}let s=l(`${n}.${t}`,e);if(s!==null)return{error:s};i[r]=e}let o=i.start_date,l=i.end_date;return typeof o=="string"&&typeof l=="string"&&l<o?{error:`${n}.endDate must not be before startDate`}:{item:i}}function xe(e,t){if(!Array.isArray(t))return{error:`${e} must be an array (send [] to clear it)`};if(t.length>de)return{error:`${e} has ${t.length} items; the server accepts at most ${de}`};let r=[],n=/* @__PURE__ */new Set;for(let a=0;a<t.length;a+=1){let i=Ne(e,a,t[a]);if("error"in i)return i;let o=i.item.ref;if(typeof o=="string"){let t=o.trim();if(n.has(t))return{error:`${e}: ref ${JSON.stringify(t)} is used twice; a ref names one item`};n.add(t)}r.push(i.item)}return{items:r}}function Ue(e,t){let r=e,n={};for(let[e,t]of Ce){let a=r[e];if(a!==void 0){if(a!==null){let t=ke[e](e,a);if(t!==null)return{error:t}}n[t]=a}}let a=r.birthDate!==void 0,i=r.birthDatePrecision!==void 0;if(a!==i||a&&r.birthDate===null!=(r.birthDatePrecision===null))return{error:"birthDate and birthDatePrecision must be sent together, both set or both null"};for(let[e,t]of Ee){let a=r[e];if(a===void 0)continue;let i=xe(e,a);if("error"in i)return i;n[t]=i.items}return Object.keys(n).length>0&&t!==void 0&&canonicalPetSpecies(t)===null?{error:"health fields need a pet Everfur reads as a dog or a cat (dog, canine, k9, puppy, cat, feline, kitten)"}:{body:n}}var qe=e=>typeof e=="string"?e:null,Le=(e,t)=>typeof t=="string"&&e.has(t)?t:null,ze=e=>typeof e=="boolean"?e:null;function Pe(e,t){return Array.isArray(e)?/* @__PURE__ */Object.freeze(e.flatMap(e=>{if(typeof e!="object"||e===null||Array.isArray(e))return[];let r=t(e);return r===null?[]:[r]})):/* @__PURE__ */Object.freeze([])}function Me(e){let t=qe(e.name);return t===null||t.length===0?null:/* @__PURE__ */Object.freeze({ref:qe(e.ref),name:t,dose:qe(e.dose),frequency:qe(e.frequency),startDate:qe(e.start_date),endDate:qe(e.end_date),notes:qe(e.notes)})}function Ke(e){let t=e.profile_version;/* @__PURE__ */
|