@trainly/react 1.0.1 → 1.0.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.
|
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
var TrainlyClient = /** @class */ (function () {
|
|
38
38
|
function TrainlyClient(config) {
|
|
39
39
|
this.scopedToken = null;
|
|
40
|
+
this.currentUserId = null;
|
|
40
41
|
this.config = config;
|
|
41
42
|
}
|
|
42
43
|
TrainlyClient.prototype.connect = function () {
|
|
@@ -53,6 +54,11 @@ var TrainlyClient = /** @class */ (function () {
|
|
|
53
54
|
if (!this.config.appSecret) {
|
|
54
55
|
throw new Error("Either appSecret or apiKey must be provided");
|
|
55
56
|
}
|
|
57
|
+
// App secret mode - provision user
|
|
58
|
+
// Ensure we use the same user ID consistently
|
|
59
|
+
if (!this.currentUserId) {
|
|
60
|
+
this.currentUserId = this.config.userId || this.generateAnonymousId();
|
|
61
|
+
}
|
|
56
62
|
return [4 /*yield*/, fetch("".concat(this.config.baseUrl, "/v1/privacy/apps/users/provision"), {
|
|
57
63
|
method: "POST",
|
|
58
64
|
headers: {
|
|
@@ -60,7 +66,7 @@ var TrainlyClient = /** @class */ (function () {
|
|
|
60
66
|
"Content-Type": "application/json",
|
|
61
67
|
},
|
|
62
68
|
body: JSON.stringify({
|
|
63
|
-
end_user_id: this.
|
|
69
|
+
end_user_id: this.currentUserId,
|
|
64
70
|
capabilities: ["ask", "upload"],
|
|
65
71
|
}),
|
|
66
72
|
})];
|
|
@@ -102,7 +108,9 @@ var TrainlyClient = /** @class */ (function () {
|
|
|
102
108
|
}
|
|
103
109
|
else {
|
|
104
110
|
headers["x-scoped-token"] = this.scopedToken;
|
|
105
|
-
|
|
111
|
+
// Use the same user ID that was used during provisioning
|
|
112
|
+
body.end_user_id =
|
|
113
|
+
this.currentUserId || this.config.userId || this.generateAnonymousId();
|
|
106
114
|
body.include_citations = options.includeCitations || false;
|
|
107
115
|
}
|
|
108
116
|
return [4 /*yield*/, fetch(url, {
|
|
@@ -167,7 +175,9 @@ var TrainlyClient = /** @class */ (function () {
|
|
|
167
175
|
"x-scoped-token": this.scopedToken,
|
|
168
176
|
},
|
|
169
177
|
body: JSON.stringify({
|
|
170
|
-
end_user_id: this.
|
|
178
|
+
end_user_id: this.currentUserId ||
|
|
179
|
+
this.config.userId ||
|
|
180
|
+
this.generateAnonymousId(),
|
|
171
181
|
filename: file.name,
|
|
172
182
|
file_type: file.type,
|
|
173
183
|
}),
|