@health-samurai/aidbox-client 0.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +137 -0
  2. package/dist/src/client.d.ts +25 -0
  3. package/dist/src/client.d.ts.map +1 -0
  4. package/dist/src/client.js +981 -0
  5. package/dist/src/fhir-http.d.ts +72 -0
  6. package/dist/src/fhir-http.d.ts.map +1 -0
  7. package/dist/src/fhir-http.js +1 -0
  8. package/dist/src/fhir-types/hl7-fhir-r4-core/BackboneElement.d.ts +5 -0
  9. package/dist/src/fhir-types/hl7-fhir-r4-core/BackboneElement.d.ts.map +1 -0
  10. package/dist/src/fhir-types/hl7-fhir-r4-core/BackboneElement.js +5 -0
  11. package/dist/src/fhir-types/hl7-fhir-r4-core/Bundle.d.ts +53 -0
  12. package/dist/src/fhir-types/hl7-fhir-r4-core/Bundle.d.ts.map +1 -0
  13. package/dist/src/fhir-types/hl7-fhir-r4-core/Bundle.js +10 -0
  14. package/dist/src/fhir-types/hl7-fhir-r4-core/CodeableConcept.d.ts +10 -0
  15. package/dist/src/fhir-types/hl7-fhir-r4-core/CodeableConcept.d.ts.map +1 -0
  16. package/dist/src/fhir-types/hl7-fhir-r4-core/CodeableConcept.js +5 -0
  17. package/dist/src/fhir-types/hl7-fhir-r4-core/Coding.d.ts +15 -0
  18. package/dist/src/fhir-types/hl7-fhir-r4-core/Coding.d.ts.map +1 -0
  19. package/dist/src/fhir-types/hl7-fhir-r4-core/Coding.js +5 -0
  20. package/dist/src/fhir-types/hl7-fhir-r4-core/DomainResource.d.ts +10 -0
  21. package/dist/src/fhir-types/hl7-fhir-r4-core/DomainResource.d.ts.map +1 -0
  22. package/dist/src/fhir-types/hl7-fhir-r4-core/DomainResource.js +10 -0
  23. package/dist/src/fhir-types/hl7-fhir-r4-core/Element.d.ts +5 -0
  24. package/dist/src/fhir-types/hl7-fhir-r4-core/Element.d.ts.map +1 -0
  25. package/dist/src/fhir-types/hl7-fhir-r4-core/Element.js +5 -0
  26. package/dist/src/fhir-types/hl7-fhir-r4-core/Identifier.d.ts +20 -0
  27. package/dist/src/fhir-types/hl7-fhir-r4-core/Identifier.d.ts.map +1 -0
  28. package/dist/src/fhir-types/hl7-fhir-r4-core/Identifier.js +5 -0
  29. package/dist/src/fhir-types/hl7-fhir-r4-core/Meta.d.ts +17 -0
  30. package/dist/src/fhir-types/hl7-fhir-r4-core/Meta.d.ts.map +1 -0
  31. package/dist/src/fhir-types/hl7-fhir-r4-core/Meta.js +5 -0
  32. package/dist/src/fhir-types/hl7-fhir-r4-core/Narrative.d.ts +9 -0
  33. package/dist/src/fhir-types/hl7-fhir-r4-core/Narrative.d.ts.map +1 -0
  34. package/dist/src/fhir-types/hl7-fhir-r4-core/Narrative.js +5 -0
  35. package/dist/src/fhir-types/hl7-fhir-r4-core/OperationOutcome.d.ts +19 -0
  36. package/dist/src/fhir-types/hl7-fhir-r4-core/OperationOutcome.d.ts.map +1 -0
  37. package/dist/src/fhir-types/hl7-fhir-r4-core/OperationOutcome.js +10 -0
  38. package/dist/src/fhir-types/hl7-fhir-r4-core/Period.d.ts +9 -0
  39. package/dist/src/fhir-types/hl7-fhir-r4-core/Period.d.ts.map +1 -0
  40. package/dist/src/fhir-types/hl7-fhir-r4-core/Period.js +5 -0
  41. package/dist/src/fhir-types/hl7-fhir-r4-core/Reference.d.ts +14 -0
  42. package/dist/src/fhir-types/hl7-fhir-r4-core/Reference.d.ts.map +1 -0
  43. package/dist/src/fhir-types/hl7-fhir-r4-core/Reference.js +5 -0
  44. package/dist/src/fhir-types/hl7-fhir-r4-core/Resource.d.ts +14 -0
  45. package/dist/src/fhir-types/hl7-fhir-r4-core/Resource.d.ts.map +1 -0
  46. package/dist/src/fhir-types/hl7-fhir-r4-core/Resource.js +10 -0
  47. package/dist/src/fhir-types/hl7-fhir-r4-core/Signature.d.ts +20 -0
  48. package/dist/src/fhir-types/hl7-fhir-r4-core/Signature.d.ts.map +1 -0
  49. package/dist/src/fhir-types/hl7-fhir-r4-core/Signature.js +5 -0
  50. package/dist/src/fhir-types/hl7-fhir-r4-core/index.d.ts +19 -0
  51. package/dist/src/fhir-types/hl7-fhir-r4-core/index.d.ts.map +1 -0
  52. package/dist/src/fhir-types/hl7-fhir-r4-core/index.js +4 -0
  53. package/dist/src/index.d.ts +8 -0
  54. package/dist/src/index.d.ts.map +1 -0
  55. package/dist/src/index.js +4 -0
  56. package/dist/src/result.d.ts +21 -0
  57. package/dist/src/result.d.ts.map +1 -0
  58. package/dist/src/result.js +36 -0
  59. package/dist/src/types.d.ts +100 -0
  60. package/dist/src/types.d.ts.map +1 -0
  61. package/dist/src/types.js +155 -0
  62. package/dist/src/utils.d.ts +3 -0
  63. package/dist/src/utils.d.ts.map +1 -0
  64. package/dist/src/utils.js +215 -0
  65. package/dist/test/client.test.d.ts +2 -0
  66. package/dist/test/client.test.d.ts.map +1 -0
  67. package/dist/test/fhir-http.test.d.ts +2 -0
  68. package/dist/test/fhir-http.test.d.ts.map +1 -0
  69. package/dist/test/result.test.d.ts +2 -0
  70. package/dist/test/result.test.d.ts.map +1 -0
  71. package/package.json +47 -0
@@ -0,0 +1,36 @@
1
+ export var Ok = function(value) {
2
+ return {
3
+ ok: true,
4
+ value: value,
5
+ isOk: function() {
6
+ return true;
7
+ },
8
+ isErr: function() {
9
+ return false;
10
+ },
11
+ map: function(f) {
12
+ return Ok(f(value));
13
+ },
14
+ mapErr: function(_f) {
15
+ return Ok(value);
16
+ }
17
+ };
18
+ };
19
+ export var Err = function(error) {
20
+ return {
21
+ ok: false,
22
+ value: error,
23
+ isOk: function() {
24
+ return false;
25
+ },
26
+ isErr: function() {
27
+ return true;
28
+ },
29
+ map: function(_f) {
30
+ return Err(error);
31
+ },
32
+ mapErr: function(f) {
33
+ return Err(f(error));
34
+ }
35
+ };
36
+ };
@@ -0,0 +1,100 @@
1
+ import type { BatchOptions, CapabilitiesOptions, ConditionalCreateOptions, ConditionalDeleteOptions, ConditionalPatchOptions, ConditionalUpdateOptions, CreateOptions, DeleteHistoryVersionOptions, DeleteOptions, HistoryOptions, OperationOptions, PatchOptions, ReadOptions, SearchOptions, TransactionOptions, UpdateOptions, ValidateOptions, VReadOptions } from "./fhir-http";
2
+ import type { Bundle, OperationOutcome, Resource } from "./fhir-types/hl7-fhir-r4-core";
3
+ import type { Result } from "./result";
4
+ export type Parameters = [string, string][];
5
+ export type Headers = Record<string, string>;
6
+ export type ClientParams = {
7
+ baseurl: string;
8
+ onResponse?: (resp: Response) => void;
9
+ };
10
+ export type User = Resource & {
11
+ email?: string;
12
+ };
13
+ export type RequestParams = {
14
+ method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
15
+ url: string;
16
+ headers?: Headers;
17
+ params?: Parameters;
18
+ body?: string;
19
+ };
20
+ export type ResponseWithMeta = {
21
+ response: Response;
22
+ responseHeaders: Headers;
23
+ duration: number;
24
+ request: RequestParams;
25
+ };
26
+ export type ResourceResponse<T> = ResponseWithMeta & {
27
+ resource: T;
28
+ };
29
+ export declare class RequestError extends Error {
30
+ request: RequestParams;
31
+ constructor(msg: string, { cause, request }: {
32
+ cause?: unknown;
33
+ request: RequestParams;
34
+ });
35
+ }
36
+ export declare class ErrorResponse extends Error {
37
+ responseWithMeta: ResponseWithMeta;
38
+ constructor(msg: string, cause: ResponseWithMeta);
39
+ }
40
+ export type FhirServerClient<TBundle = Bundle, TOperationOutcome = OperationOutcome, TUser = User> = {
41
+ getBaseURL: () => string;
42
+ /**
43
+ * Untyped request.
44
+ *
45
+ * Example usage:
46
+ *
47
+ * ```typescript
48
+ * const result = client.rawRequest({
49
+ * method: "GET",
50
+ * url: "/fhir/Patient/pt-1",
51
+ * })
52
+ * ```
53
+ */
54
+ rawRequest: (params: RequestParams) => Promise<ResponseWithMeta>;
55
+ /**
56
+ * Typed request
57
+ *
58
+ * Example usage:
59
+ *
60
+ * ```typescript
61
+ * const result = client.request<Patient>({
62
+ * method: "GET",
63
+ * url: "/fhir/Patient/pt-1",
64
+ * })
65
+ *
66
+ * if (isOk(result)) {
67
+ * const { value } = result;
68
+ * // work with value as a Patient type
69
+ * } else {
70
+ * const { error } = result;
71
+ * // work with error as an OperationOutcome type.
72
+ * }
73
+ * ```
74
+ */
75
+ request: <T>(params: RequestParams) => Promise<Result<ResourceResponse<T>, ResourceResponse<TOperationOutcome>>>;
76
+ /** Performs a request to `/auth/logout`. */
77
+ performLogout: () => Promise<Response>;
78
+ /** Performs a request to `/auth/userinfo`. */
79
+ fetchUserInfo: () => Promise<TUser>;
80
+ read: <T>(opts: ReadOptions) => Promise<Result<ResourceResponse<T>, ResourceResponse<TOperationOutcome>>>;
81
+ vread: <T>(opts: VReadOptions) => Promise<Result<ResourceResponse<T>, ResourceResponse<TOperationOutcome>>>;
82
+ search: (opts: SearchOptions) => Promise<Result<ResourceResponse<TBundle>, ResourceResponse<TOperationOutcome>>>;
83
+ create: <T>(opts: CreateOptions) => Promise<Result<ResourceResponse<T>, ResourceResponse<TOperationOutcome>>>;
84
+ conditionalCreate: <T>(opts: ConditionalCreateOptions) => Promise<Result<ResourceResponse<T>, ResourceResponse<TOperationOutcome>>>;
85
+ update: <T>(opts: UpdateOptions) => Promise<Result<ResourceResponse<T>, ResourceResponse<TOperationOutcome>>>;
86
+ conditionalUpdate: <T>(opts: ConditionalUpdateOptions) => Promise<Result<ResourceResponse<T>, ResourceResponse<TOperationOutcome>>>;
87
+ patch: <T>(opts: PatchOptions) => Promise<Result<ResourceResponse<T>, ResourceResponse<TOperationOutcome>>>;
88
+ conditionalPatch: <T>(opts: ConditionalPatchOptions) => Promise<Result<ResourceResponse<T>, ResourceResponse<TOperationOutcome>>>;
89
+ delete: <T>(opts: DeleteOptions) => Promise<Result<ResourceResponse<T | undefined>, ResourceResponse<TOperationOutcome>>>;
90
+ deleteHistory: <T>(opts: DeleteOptions) => Promise<Result<ResourceResponse<T>, ResourceResponse<TOperationOutcome>>>;
91
+ deleteHistoryVersion: <T>(opts: DeleteHistoryVersionOptions) => Promise<Result<ResourceResponse<T>, ResourceResponse<TOperationOutcome>>>;
92
+ conditionalDelete: <T>(opts: ConditionalDeleteOptions) => Promise<Result<ResourceResponse<T>, ResourceResponse<TOperationOutcome>>>;
93
+ history: (opts: HistoryOptions) => Promise<Result<ResourceResponse<TBundle>, ResourceResponse<TOperationOutcome>>>;
94
+ capabilities: (opts: CapabilitiesOptions) => Promise<Result<ResourceResponse<unknown>, ResourceResponse<TOperationOutcome>>>;
95
+ batch: (opts: BatchOptions) => Promise<Result<ResourceResponse<unknown>, ResourceResponse<TOperationOutcome>>>;
96
+ transaction: (opts: TransactionOptions) => Promise<Result<ResourceResponse<unknown>, ResourceResponse<TOperationOutcome>>>;
97
+ operation: <T>(opts: OperationOptions) => Promise<Result<ResourceResponse<T>, ResourceResponse<TOperationOutcome>>>;
98
+ validate: (opts: ValidateOptions) => Promise<Result<ResourceResponse<TOperationOutcome>, ResourceResponse<TOperationOutcome>>>;
99
+ };
100
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,YAAY,EACZ,mBAAmB,EACnB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,aAAa,EACb,2BAA2B,EAC3B,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACX,MAAM,EACN,gBAAgB,EAChB,QAAQ,EACR,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;AAC5C,MAAM,MAAM,OAAO,GAAG,MAAM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pB,IAAI,EAAE,wBAAwB,KAC1B,OAAO,CACX,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAChE,CAAC;IACF,OAAO,EAAE,CACR,IAAI,EAAE,cAAc,KAChB,OAAO,CACX,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CACtE,CAAC;IACF,YAAY,EAAE,CACb,IAAI,EAAE,mBAAmB,KACrB,OAAO,CACX,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CACtE,CAAC;IACF,KAAK,EAAE,CACN,IAAI,EAAE,YAAY,KACd,OAAO,CACX,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CACtE,CAAC;IACF,WAAW,EAAE,CACZ,IAAI,EAAE,kBAAkB,KACpB,OAAO,CACX,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CACtE,CAAC;IACF,SAAS,EAAE,CAAC,CAAC,EACZ,IAAI,EAAE,gBAAgB,KAClB,OAAO,CACX,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAChE,CAAC;IACF,QAAQ,EAAE,CACT,IAAI,EAAE,eAAe,KACjB,OAAO,CACX,MAAM,CACL,gBAAgB,CAAC,iBAAiB,CAAC,EACnC,gBAAgB,CAAC,iBAAiB,CAAC,CACnC,CACD,CAAC;CACF,CAAC"}
@@ -0,0 +1,155 @@
1
+ function _assert_this_initialized(self) {
2
+ if (self === void 0) {
3
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4
+ }
5
+ return self;
6
+ }
7
+ function _call_super(_this, derived, args) {
8
+ derived = _get_prototype_of(derived);
9
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
10
+ }
11
+ function _class_call_check(instance, Constructor) {
12
+ if (!(instance instanceof Constructor)) {
13
+ throw new TypeError("Cannot call a class as a function");
14
+ }
15
+ }
16
+ function _construct(Parent, args, Class) {
17
+ if (_is_native_reflect_construct()) {
18
+ _construct = Reflect.construct;
19
+ } else {
20
+ _construct = function construct(Parent, args, Class) {
21
+ var a = [
22
+ null
23
+ ];
24
+ a.push.apply(a, args);
25
+ var Constructor = Function.bind.apply(Parent, a);
26
+ var instance = new Constructor();
27
+ if (Class) _set_prototype_of(instance, Class.prototype);
28
+ return instance;
29
+ };
30
+ }
31
+ return _construct.apply(null, arguments);
32
+ }
33
+ function _define_property(obj, key, value) {
34
+ if (key in obj) {
35
+ Object.defineProperty(obj, key, {
36
+ value: value,
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true
40
+ });
41
+ } else {
42
+ obj[key] = value;
43
+ }
44
+ return obj;
45
+ }
46
+ function _get_prototype_of(o) {
47
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
48
+ return o.__proto__ || Object.getPrototypeOf(o);
49
+ };
50
+ return _get_prototype_of(o);
51
+ }
52
+ function _inherits(subClass, superClass) {
53
+ if (typeof superClass !== "function" && superClass !== null) {
54
+ throw new TypeError("Super expression must either be null or a function");
55
+ }
56
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
57
+ constructor: {
58
+ value: subClass,
59
+ writable: true,
60
+ configurable: true
61
+ }
62
+ });
63
+ if (superClass) _set_prototype_of(subClass, superClass);
64
+ }
65
+ function _is_native_function(fn) {
66
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
67
+ }
68
+ function _possible_constructor_return(self, call) {
69
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
70
+ return call;
71
+ }
72
+ return _assert_this_initialized(self);
73
+ }
74
+ function _set_prototype_of(o, p) {
75
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
76
+ o.__proto__ = p;
77
+ return o;
78
+ };
79
+ return _set_prototype_of(o, p);
80
+ }
81
+ function _type_of(obj) {
82
+ "@swc/helpers - typeof";
83
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
84
+ }
85
+ function _wrap_native_super(Class) {
86
+ var _cache = typeof Map === "function" ? new Map() : undefined;
87
+ _wrap_native_super = function wrapNativeSuper(Class) {
88
+ if (Class === null || !_is_native_function(Class)) return Class;
89
+ if (typeof Class !== "function") {
90
+ throw new TypeError("Super expression must either be null or a function");
91
+ }
92
+ if (typeof _cache !== "undefined") {
93
+ if (_cache.has(Class)) return _cache.get(Class);
94
+ _cache.set(Class, Wrapper);
95
+ }
96
+ function Wrapper() {
97
+ return _construct(Class, arguments, _get_prototype_of(this).constructor);
98
+ }
99
+ Wrapper.prototype = Object.create(Class.prototype, {
100
+ constructor: {
101
+ value: Wrapper,
102
+ enumerable: false,
103
+ writable: true,
104
+ configurable: true
105
+ }
106
+ });
107
+ return _set_prototype_of(Wrapper, Class);
108
+ };
109
+ return _wrap_native_super(Class);
110
+ }
111
+ function _is_native_reflect_construct() {
112
+ try {
113
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
114
+ } catch (_) {}
115
+ return (_is_native_reflect_construct = function() {
116
+ return !!result;
117
+ })();
118
+ }
119
+ export var RequestError = /*#__PURE__*/ function(Error1) {
120
+ "use strict";
121
+ _inherits(RequestError, Error1);
122
+ function RequestError(msg, param) {
123
+ var cause = param.cause, request = param.request;
124
+ _class_call_check(this, RequestError);
125
+ var _this;
126
+ if (cause) _this = _call_super(this, RequestError, [
127
+ msg,
128
+ {
129
+ cause: cause
130
+ }
131
+ ]), _define_property(_this, "request", void 0);
132
+ else _this = _call_super(this, RequestError, [
133
+ msg
134
+ ]), _define_property(_this, "request", void 0);
135
+ _assert_this_initialized(_this).name = "RequestError";
136
+ _assert_this_initialized(_this).request = request;
137
+ return _assert_this_initialized(_this);
138
+ }
139
+ return RequestError;
140
+ }(_wrap_native_super(Error));
141
+ export var ErrorResponse = /*#__PURE__*/ function(Error1) {
142
+ "use strict";
143
+ _inherits(ErrorResponse, Error1);
144
+ function ErrorResponse(msg, cause) {
145
+ _class_call_check(this, ErrorResponse);
146
+ var _this;
147
+ _this = _call_super(this, ErrorResponse, [
148
+ msg
149
+ ]), _define_property(_this, "responseWithMeta", void 0);
150
+ _this.responseWithMeta = cause;
151
+ _this.name = "ErrorResponse";
152
+ return _this;
153
+ }
154
+ return ErrorResponse;
155
+ }(_wrap_native_super(Error));
@@ -0,0 +1,3 @@
1
+ import type { ResponseWithMeta } from "./types";
2
+ export declare const coerceBody: <T>(meta: ResponseWithMeta) => Promise<T>;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAYhD,eAAO,MAAM,UAAU,GAAU,CAAC,EAAE,MAAM,gBAAgB,KAAG,OAAO,CAAC,CAAC,CA2BrE,CAAC"}
@@ -0,0 +1,215 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ function _instanceof(left, right) {
31
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
32
+ return !!right[Symbol.hasInstance](left);
33
+ } else {
34
+ return left instanceof right;
35
+ }
36
+ }
37
+ function _ts_generator(thisArg, body) {
38
+ var f, y, t, _ = {
39
+ label: 0,
40
+ sent: function() {
41
+ if (t[0] & 1) throw t[1];
42
+ return t[1];
43
+ },
44
+ trys: [],
45
+ ops: []
46
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
47
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
48
+ return this;
49
+ }), g;
50
+ function verb(n) {
51
+ return function(v) {
52
+ return step([
53
+ n,
54
+ v
55
+ ]);
56
+ };
57
+ }
58
+ function step(op) {
59
+ if (f) throw new TypeError("Generator is already executing.");
60
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
61
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
62
+ if (y = 0, t) op = [
63
+ op[0] & 2,
64
+ t.value
65
+ ];
66
+ switch(op[0]){
67
+ case 0:
68
+ case 1:
69
+ t = op;
70
+ break;
71
+ case 4:
72
+ _.label++;
73
+ return {
74
+ value: op[1],
75
+ done: false
76
+ };
77
+ case 5:
78
+ _.label++;
79
+ y = op[1];
80
+ op = [
81
+ 0
82
+ ];
83
+ continue;
84
+ case 7:
85
+ op = _.ops.pop();
86
+ _.trys.pop();
87
+ continue;
88
+ default:
89
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
90
+ _ = 0;
91
+ continue;
92
+ }
93
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
94
+ _.label = op[1];
95
+ break;
96
+ }
97
+ if (op[0] === 6 && _.label < t[1]) {
98
+ _.label = t[1];
99
+ t = op;
100
+ break;
101
+ }
102
+ if (t && _.label < t[2]) {
103
+ _.label = t[2];
104
+ _.ops.push(op);
105
+ break;
106
+ }
107
+ if (t[2]) _.ops.pop();
108
+ _.trys.pop();
109
+ continue;
110
+ }
111
+ op = body.call(thisArg, _);
112
+ } catch (e) {
113
+ op = [
114
+ 6,
115
+ e
116
+ ];
117
+ y = 0;
118
+ } finally{
119
+ f = t = 0;
120
+ }
121
+ if (op[0] & 5) throw op[1];
122
+ return {
123
+ value: op[0] ? op[1] : void 0,
124
+ done: true
125
+ };
126
+ }
127
+ }
128
+ import YAML from "yaml";
129
+ import { ErrorResponse } from "./types";
130
+ var normalizeContentType = function(contentType) {
131
+ var semicolon = contentType.indexOf(";");
132
+ if (semicolon !== -1) {
133
+ return contentType.substring(0, semicolon).toLowerCase();
134
+ } else {
135
+ return contentType.toLowerCase();
136
+ }
137
+ };
138
+ export var coerceBody = function(meta) {
139
+ return _async_to_generator(function() {
140
+ var contentType, responseCopy, _, _1, e, message;
141
+ return _ts_generator(this, function(_state) {
142
+ switch(_state.label){
143
+ case 0:
144
+ contentType = meta.responseHeaders["content-type"];
145
+ if (!contentType) throw new ErrorResponse("can't coerce body to the specifyed type: server didn't specify response content-type", meta);
146
+ responseCopy = meta.response.clone();
147
+ _state.label = 1;
148
+ case 1:
149
+ _state.trys.push([
150
+ 1,
151
+ 7,
152
+ ,
153
+ 8
154
+ ]);
155
+ _ = normalizeContentType(contentType);
156
+ switch(_){
157
+ case "application/json":
158
+ return [
159
+ 3,
160
+ 2
161
+ ];
162
+ case "application/fhir+json":
163
+ return [
164
+ 3,
165
+ 2
166
+ ];
167
+ case "text/yaml":
168
+ return [
169
+ 3,
170
+ 4
171
+ ];
172
+ }
173
+ return [
174
+ 3,
175
+ 6
176
+ ];
177
+ case 2:
178
+ return [
179
+ 4,
180
+ responseCopy.json()
181
+ ];
182
+ case 3:
183
+ return [
184
+ 2,
185
+ _state.sent()
186
+ ];
187
+ case 4:
188
+ _1 = YAML.parse;
189
+ return [
190
+ 4,
191
+ responseCopy.text()
192
+ ];
193
+ case 5:
194
+ return [
195
+ 2,
196
+ _1.apply(YAML, [
197
+ _state.sent()
198
+ ])
199
+ ];
200
+ case 6:
201
+ return [
202
+ 3,
203
+ 8
204
+ ];
205
+ case 7:
206
+ e = _state.sent();
207
+ message = _instanceof(e, Error) ? e.message : "unknown error";
208
+ throw new ErrorResponse("failed to coerce body: ".concat(message), meta);
209
+ case 8:
210
+ // default:
211
+ throw new ErrorResponse("failed to coerce body: unknown content-type ".concat(contentType), meta);
212
+ }
213
+ });
214
+ })();
215
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=client.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.test.d.ts","sourceRoot":"","sources":["../../test/client.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=fhir-http.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fhir-http.test.d.ts","sourceRoot":"","sources":["../../test/fhir-http.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=result.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.test.d.ts","sourceRoot":"","sources":["../../test/result.test.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@health-samurai/aidbox-client",
3
+ "version": "0.0.0-alpha.1",
4
+ "description": "A client library for communicating with Aidbox",
5
+ "author": "Health Samurai",
6
+ "type": "module",
7
+ "main": "./dist/src/index.js",
8
+ "types": "./dist/src/index.types.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "exports": {
13
+ ".": "./dist/src/index.js"
14
+ },
15
+ "scripts": {
16
+ "build": "rm -rf dist && mkdir -p dist && swc src -d dist -D && tsc -b --force && echo success",
17
+ "format": "biome format",
18
+ "format:check": "biome format",
19
+ "format:fix": "biome format --write",
20
+ "lint": "biome check",
21
+ "lint:check": "biome check",
22
+ "lint:fix": "biome check --write",
23
+ "typecheck": "tsc -b --noEmit",
24
+ "generate-types": "tsx scripts/generate-types.ts",
25
+ "test": "vitest run",
26
+ "test:watch": "vitest watch",
27
+ "doc": "typedoc"
28
+ },
29
+ "dependencies": {
30
+ "yaml": "^2.8.1"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/HealthSamurai/aidbox-ts-sdk"
38
+ },
39
+ "devDependencies": {
40
+ "@atomic-ehr/codegen": "^0.0.3",
41
+ "@types/node": "^24.2.0",
42
+ "tsx": "^4.20.4",
43
+ "typedoc": "^0.28.14",
44
+ "typescript": "~5.8.3",
45
+ "vitest": "^3.2.4"
46
+ }
47
+ }