@health-samurai/aidbox-client 0.0.0-alpha.1 → 0.0.0-alpha.3
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/README.md +233 -74
- package/dist/src/auth-providers.d.ts +23 -0
- package/dist/src/auth-providers.d.ts.map +1 -0
- package/dist/src/auth-providers.js +322 -0
- package/dist/src/client.d.ts +508 -11
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +1473 -759
- package/dist/src/fhir-types/hl7-fhir-r4-core/Address.d.ts +26 -0
- package/dist/src/fhir-types/hl7-fhir-r4-core/Address.d.ts.map +1 -0
- package/dist/src/fhir-types/hl7-fhir-r4-core/Address.js +5 -0
- package/dist/src/fhir-types/hl7-fhir-r4-core/ContactPoint.d.ts +16 -0
- package/dist/src/fhir-types/hl7-fhir-r4-core/ContactPoint.d.ts.map +1 -0
- package/dist/src/fhir-types/hl7-fhir-r4-core/ContactPoint.js +5 -0
- package/dist/src/fhir-types/hl7-fhir-r4-core/DomainResource.d.ts +1 -1
- package/dist/src/fhir-types/hl7-fhir-r4-core/DomainResource.d.ts.map +1 -1
- package/dist/src/fhir-types/hl7-fhir-r4-core/HumanName.d.ts +20 -0
- package/dist/src/fhir-types/hl7-fhir-r4-core/HumanName.d.ts.map +1 -0
- package/dist/src/fhir-types/hl7-fhir-r4-core/HumanName.js +5 -0
- package/dist/src/fhir-types/hl7-fhir-r4-core/Patient.d.ts +58 -0
- package/dist/src/fhir-types/hl7-fhir-r4-core/Patient.d.ts.map +1 -0
- package/dist/src/fhir-types/hl7-fhir-r4-core/Patient.js +10 -0
- package/dist/src/fhir-types/hl7-fhir-r4-core/Resource.d.ts +1 -1
- package/dist/src/fhir-types/hl7-fhir-r4-core/Resource.d.ts.map +1 -1
- package/dist/src/fhir-types/hl7-fhir-r4-core/index.d.ts +5 -0
- package/dist/src/fhir-types/hl7-fhir-r4-core/index.d.ts.map +1 -1
- package/dist/src/fhir-types/hl7-fhir-r4-core/index.js +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/result.d.ts +114 -3
- package/dist/src/result.d.ts.map +1 -1
- package/dist/src/result.js +6 -2
- package/dist/src/types.d.ts +110 -66
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +10 -2
- package/package.json +48 -46
- package/dist/src/fhir-http.d.ts +0 -72
- package/dist/src/fhir-http.d.ts.map +0 -1
- package/dist/src/fhir-http.js +0 -1
|
@@ -0,0 +1,322 @@
|
|
|
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 _check_private_redeclaration(obj, privateCollection) {
|
|
31
|
+
if (privateCollection.has(obj)) {
|
|
32
|
+
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function _class_call_check(instance, Constructor) {
|
|
36
|
+
if (!(instance instanceof Constructor)) {
|
|
37
|
+
throw new TypeError("Cannot call a class as a function");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function _class_private_method_get(receiver, privateSet, fn) {
|
|
41
|
+
if (!privateSet.has(receiver)) {
|
|
42
|
+
throw new TypeError("attempted to get private field on non-instance");
|
|
43
|
+
}
|
|
44
|
+
return fn;
|
|
45
|
+
}
|
|
46
|
+
function _class_private_method_init(obj, privateSet) {
|
|
47
|
+
_check_private_redeclaration(obj, privateSet);
|
|
48
|
+
privateSet.add(obj);
|
|
49
|
+
}
|
|
50
|
+
function _defineProperties(target, props) {
|
|
51
|
+
for(var i = 0; i < props.length; i++){
|
|
52
|
+
var descriptor = props[i];
|
|
53
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
54
|
+
descriptor.configurable = true;
|
|
55
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
56
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
60
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
61
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
62
|
+
return Constructor;
|
|
63
|
+
}
|
|
64
|
+
function _define_property(obj, key, value) {
|
|
65
|
+
if (key in obj) {
|
|
66
|
+
Object.defineProperty(obj, key, {
|
|
67
|
+
value: value,
|
|
68
|
+
enumerable: true,
|
|
69
|
+
configurable: true,
|
|
70
|
+
writable: true
|
|
71
|
+
});
|
|
72
|
+
} else {
|
|
73
|
+
obj[key] = value;
|
|
74
|
+
}
|
|
75
|
+
return obj;
|
|
76
|
+
}
|
|
77
|
+
function _instanceof(left, right) {
|
|
78
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
79
|
+
return !!right[Symbol.hasInstance](left);
|
|
80
|
+
} else {
|
|
81
|
+
return left instanceof right;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function _ts_generator(thisArg, body) {
|
|
85
|
+
var f, y, t, _ = {
|
|
86
|
+
label: 0,
|
|
87
|
+
sent: function() {
|
|
88
|
+
if (t[0] & 1) throw t[1];
|
|
89
|
+
return t[1];
|
|
90
|
+
},
|
|
91
|
+
trys: [],
|
|
92
|
+
ops: []
|
|
93
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
94
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
95
|
+
return this;
|
|
96
|
+
}), g;
|
|
97
|
+
function verb(n) {
|
|
98
|
+
return function(v) {
|
|
99
|
+
return step([
|
|
100
|
+
n,
|
|
101
|
+
v
|
|
102
|
+
]);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function step(op) {
|
|
106
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
107
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
108
|
+
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;
|
|
109
|
+
if (y = 0, t) op = [
|
|
110
|
+
op[0] & 2,
|
|
111
|
+
t.value
|
|
112
|
+
];
|
|
113
|
+
switch(op[0]){
|
|
114
|
+
case 0:
|
|
115
|
+
case 1:
|
|
116
|
+
t = op;
|
|
117
|
+
break;
|
|
118
|
+
case 4:
|
|
119
|
+
_.label++;
|
|
120
|
+
return {
|
|
121
|
+
value: op[1],
|
|
122
|
+
done: false
|
|
123
|
+
};
|
|
124
|
+
case 5:
|
|
125
|
+
_.label++;
|
|
126
|
+
y = op[1];
|
|
127
|
+
op = [
|
|
128
|
+
0
|
|
129
|
+
];
|
|
130
|
+
continue;
|
|
131
|
+
case 7:
|
|
132
|
+
op = _.ops.pop();
|
|
133
|
+
_.trys.pop();
|
|
134
|
+
continue;
|
|
135
|
+
default:
|
|
136
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
137
|
+
_ = 0;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
141
|
+
_.label = op[1];
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
145
|
+
_.label = t[1];
|
|
146
|
+
t = op;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
if (t && _.label < t[2]) {
|
|
150
|
+
_.label = t[2];
|
|
151
|
+
_.ops.push(op);
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
if (t[2]) _.ops.pop();
|
|
155
|
+
_.trys.pop();
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
op = body.call(thisArg, _);
|
|
159
|
+
} catch (e) {
|
|
160
|
+
op = [
|
|
161
|
+
6,
|
|
162
|
+
e
|
|
163
|
+
];
|
|
164
|
+
y = 0;
|
|
165
|
+
} finally{
|
|
166
|
+
f = t = 0;
|
|
167
|
+
}
|
|
168
|
+
if (op[0] & 5) throw op[1];
|
|
169
|
+
return {
|
|
170
|
+
value: op[0] ? op[1] : void 0,
|
|
171
|
+
done: true
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
var _checkSession = /*#__PURE__*/ new WeakSet();
|
|
176
|
+
export var BrowserAuthProvider = /*#__PURE__*/ function() {
|
|
177
|
+
"use strict";
|
|
178
|
+
function BrowserAuthProvider(baseUrl) {
|
|
179
|
+
_class_call_check(this, BrowserAuthProvider);
|
|
180
|
+
_class_private_method_init(this, _checkSession);
|
|
181
|
+
/** @ignore */ _define_property(this, "baseUrl", void 0);
|
|
182
|
+
this.baseUrl = baseUrl;
|
|
183
|
+
}
|
|
184
|
+
_create_class(BrowserAuthProvider, [
|
|
185
|
+
{
|
|
186
|
+
key: "establishSession",
|
|
187
|
+
value: /**
|
|
188
|
+
* Checks if the session is already authenticated, and if not, redirects to the login page.
|
|
189
|
+
*/ function establishSession() {
|
|
190
|
+
return _async_to_generator(function() {
|
|
191
|
+
var encodedLocation, redirectTo;
|
|
192
|
+
return _ts_generator(this, function(_state) {
|
|
193
|
+
switch(_state.label){
|
|
194
|
+
case 0:
|
|
195
|
+
return [
|
|
196
|
+
4,
|
|
197
|
+
_class_private_method_get(this, _checkSession, checkSession).call(this)
|
|
198
|
+
];
|
|
199
|
+
case 1:
|
|
200
|
+
if (!_state.sent()) {
|
|
201
|
+
encodedLocation = encodeURIComponent(btoa(window.location.href));
|
|
202
|
+
redirectTo = "".concat(this.baseUrl, "/auth/login?redirect_to=").concat(encodedLocation);
|
|
203
|
+
window.location.href = redirectTo;
|
|
204
|
+
}
|
|
205
|
+
return [
|
|
206
|
+
2
|
|
207
|
+
];
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}).call(this);
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
key: "revokeSession",
|
|
215
|
+
value: /**
|
|
216
|
+
* Sends a POST request to `baseurl/auth/logout`.
|
|
217
|
+
*/ function revokeSession() {
|
|
218
|
+
return _async_to_generator(function() {
|
|
219
|
+
return _ts_generator(this, function(_state) {
|
|
220
|
+
switch(_state.label){
|
|
221
|
+
case 0:
|
|
222
|
+
return [
|
|
223
|
+
4,
|
|
224
|
+
fetch(new URL("/auth/logout", this.baseUrl), {
|
|
225
|
+
method: "POST",
|
|
226
|
+
headers: {
|
|
227
|
+
"content-type": "application/json",
|
|
228
|
+
accept: "application/json"
|
|
229
|
+
},
|
|
230
|
+
credentials: "include"
|
|
231
|
+
})
|
|
232
|
+
];
|
|
233
|
+
case 1:
|
|
234
|
+
_state.sent();
|
|
235
|
+
return [
|
|
236
|
+
2
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}).call(this);
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
key: "fetch",
|
|
245
|
+
value: /**
|
|
246
|
+
* A thin wrapper around `fetch` function.
|
|
247
|
+
* Checks if the client is authorized to perform a request, and redirects to a login page if not.
|
|
248
|
+
*
|
|
249
|
+
* Accepts the same arguments as `fetch`.
|
|
250
|
+
*/ function fetch1(input, init) {
|
|
251
|
+
return _async_to_generator(function() {
|
|
252
|
+
var url, i, response;
|
|
253
|
+
return _ts_generator(this, function(_state) {
|
|
254
|
+
switch(_state.label){
|
|
255
|
+
case 0:
|
|
256
|
+
if (_instanceof(input, Request)) url = input.url;
|
|
257
|
+
else url = input.toString();
|
|
258
|
+
if (!url.startsWith(this.baseUrl)) throw Error("url of the request must start with baseUrl");
|
|
259
|
+
i = init !== null && init !== void 0 ? init : {};
|
|
260
|
+
i.credentials = "include";
|
|
261
|
+
return [
|
|
262
|
+
4,
|
|
263
|
+
fetch(input, i)
|
|
264
|
+
];
|
|
265
|
+
case 1:
|
|
266
|
+
response = _state.sent();
|
|
267
|
+
if (!(response.status === 401)) return [
|
|
268
|
+
3,
|
|
269
|
+
3
|
|
270
|
+
];
|
|
271
|
+
return [
|
|
272
|
+
4,
|
|
273
|
+
this.establishSession()
|
|
274
|
+
];
|
|
275
|
+
case 2:
|
|
276
|
+
_state.sent();
|
|
277
|
+
throw new Error("unauthorized");
|
|
278
|
+
case 3:
|
|
279
|
+
return [
|
|
280
|
+
2,
|
|
281
|
+
response
|
|
282
|
+
];
|
|
283
|
+
case 4:
|
|
284
|
+
return [
|
|
285
|
+
2
|
|
286
|
+
];
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}).call(this);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
]);
|
|
293
|
+
return BrowserAuthProvider;
|
|
294
|
+
} // TODO: backend auth provider
|
|
295
|
+
();
|
|
296
|
+
function checkSession() {
|
|
297
|
+
return _async_to_generator(function() {
|
|
298
|
+
var response;
|
|
299
|
+
return _ts_generator(this, function(_state) {
|
|
300
|
+
switch(_state.label){
|
|
301
|
+
case 0:
|
|
302
|
+
return [
|
|
303
|
+
4,
|
|
304
|
+
fetch(new URL("/auth/userinfo", this.baseUrl), {
|
|
305
|
+
method: "GET",
|
|
306
|
+
headers: {
|
|
307
|
+
"content-type": "application/json",
|
|
308
|
+
accept: "application/json"
|
|
309
|
+
},
|
|
310
|
+
credentials: "include"
|
|
311
|
+
})
|
|
312
|
+
];
|
|
313
|
+
case 1:
|
|
314
|
+
response = _state.sent();
|
|
315
|
+
return [
|
|
316
|
+
2,
|
|
317
|
+
response.status !== 401
|
|
318
|
+
];
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}).call(this);
|
|
322
|
+
}
|