@hipnation-truth/sdk 0.26.18 → 0.26.19
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/react.js +61 -34
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -3125,6 +3125,7 @@ function useNotifications(options) {
|
|
|
3125
3125
|
const sdkContext = useTruthSdkContext();
|
|
3126
3126
|
const apiBaseUrl = (_b = (_a = options.apiBaseUrl) != null ? _a : sdkContext == null ? void 0 : sdkContext.apiBaseUrl) != null ? _b : "";
|
|
3127
3127
|
const apiKey = (_d = (_c = options.apiKey) != null ? _c : sdkContext == null ? void 0 : sdkContext.apiKey) != null ? _d : "";
|
|
3128
|
+
const getAuthToken = sdkContext == null ? void 0 : sdkContext.getAuthToken;
|
|
3128
3129
|
const [permissionStatus, setPermissionStatus] = (0, import_react6.useState)("unknown");
|
|
3129
3130
|
const [devicePushToken, setDevicePushToken] = (0, import_react6.useState)(null);
|
|
3130
3131
|
const expoRef = (0, import_react6.useRef)(null);
|
|
@@ -3215,10 +3216,10 @@ function useNotifications(options) {
|
|
|
3215
3216
|
`${apiBaseUrl}/api/notifications/devices/register`,
|
|
3216
3217
|
{
|
|
3217
3218
|
method: "POST",
|
|
3218
|
-
headers:
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3219
|
+
headers: yield buildAuthHeaders(
|
|
3220
|
+
{ apiKey, getAuthToken },
|
|
3221
|
+
{ json: true, requireUserToken: true }
|
|
3222
|
+
),
|
|
3222
3223
|
body: JSON.stringify({
|
|
3223
3224
|
userId: options.userId,
|
|
3224
3225
|
platform: "web",
|
|
@@ -3267,14 +3268,23 @@ function useNotifications(options) {
|
|
|
3267
3268
|
if (!apiBaseUrl || !apiKey) {
|
|
3268
3269
|
return { ok: false, reason: "missing_truth_config" };
|
|
3269
3270
|
}
|
|
3271
|
+
let nativeHeaders;
|
|
3272
|
+
try {
|
|
3273
|
+
nativeHeaders = yield buildAuthHeaders(
|
|
3274
|
+
{ apiKey, getAuthToken },
|
|
3275
|
+
{ json: true, requireUserToken: true }
|
|
3276
|
+
);
|
|
3277
|
+
} catch (err) {
|
|
3278
|
+
return {
|
|
3279
|
+
ok: false,
|
|
3280
|
+
reason: `missing_user_token: ${err instanceof Error ? err.message : String(err)}`
|
|
3281
|
+
};
|
|
3282
|
+
}
|
|
3270
3283
|
const res = yield fetch(
|
|
3271
3284
|
`${apiBaseUrl}/api/notifications/devices/register`,
|
|
3272
3285
|
{
|
|
3273
3286
|
method: "POST",
|
|
3274
|
-
headers:
|
|
3275
|
-
"Content-Type": "application/json",
|
|
3276
|
-
"X-API-Key": apiKey
|
|
3277
|
-
},
|
|
3287
|
+
headers: nativeHeaders,
|
|
3278
3288
|
body: JSON.stringify(__spreadValues({
|
|
3279
3289
|
userId: options.userId,
|
|
3280
3290
|
platform,
|
|
@@ -3296,6 +3306,7 @@ function useNotifications(options) {
|
|
|
3296
3306
|
}), [
|
|
3297
3307
|
apiBaseUrl,
|
|
3298
3308
|
apiKey,
|
|
3309
|
+
getAuthToken,
|
|
3299
3310
|
options.userId,
|
|
3300
3311
|
options.appVersion,
|
|
3301
3312
|
options.serviceWorkerPath
|
|
@@ -3304,17 +3315,20 @@ function useNotifications(options) {
|
|
|
3304
3315
|
if (!devicePushToken) {
|
|
3305
3316
|
return;
|
|
3306
3317
|
}
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
}
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3318
|
+
try {
|
|
3319
|
+
const headers = yield buildAuthHeaders(
|
|
3320
|
+
{ apiKey, getAuthToken },
|
|
3321
|
+
{ json: true, requireUserToken: true }
|
|
3322
|
+
);
|
|
3323
|
+
yield fetch(`${apiBaseUrl}/api/notifications/devices/unregister`, {
|
|
3324
|
+
method: "POST",
|
|
3325
|
+
headers,
|
|
3326
|
+
body: JSON.stringify({ nativeToken: devicePushToken })
|
|
3327
|
+
});
|
|
3328
|
+
} catch (e) {
|
|
3329
|
+
}
|
|
3316
3330
|
setDevicePushToken(null);
|
|
3317
|
-
}), [apiBaseUrl, apiKey, devicePushToken]);
|
|
3331
|
+
}), [apiBaseUrl, apiKey, getAuthToken, devicePushToken]);
|
|
3318
3332
|
const addReceivedListener = (0, import_react6.useCallback)(
|
|
3319
3333
|
(listener) => {
|
|
3320
3334
|
if (isWebRef.current) {
|
|
@@ -3476,20 +3490,25 @@ function useNotificationsActions() {
|
|
|
3476
3490
|
const sdkContext = useTruthSdkContext();
|
|
3477
3491
|
const apiBaseUrl = (_a = sdkContext == null ? void 0 : sdkContext.apiBaseUrl) != null ? _a : "";
|
|
3478
3492
|
const apiKey = (_b = sdkContext == null ? void 0 : sdkContext.apiKey) != null ? _b : "";
|
|
3493
|
+
const getAuthToken = sdkContext == null ? void 0 : sdkContext.getAuthToken;
|
|
3479
3494
|
const post = (0, import_react6.useCallback)(
|
|
3480
|
-
(path, body) => __async(null, null, function* () {
|
|
3495
|
+
(path, body, opts) => __async(null, null, function* () {
|
|
3481
3496
|
if (!apiBaseUrl || !apiKey) {
|
|
3482
3497
|
throw new Error(
|
|
3483
3498
|
"useNotificationsActions: missing apiBaseUrl/apiKey \u2014 wrap in <TruthProvider> or pass options"
|
|
3484
3499
|
);
|
|
3485
3500
|
}
|
|
3501
|
+
const headers = (opts == null ? void 0 : opts.requireUserToken) ? yield buildAuthHeaders(
|
|
3502
|
+
{ apiKey, getAuthToken },
|
|
3503
|
+
{ json: true, requireUserToken: true }
|
|
3504
|
+
) : {
|
|
3505
|
+
"Content-Type": "application/json",
|
|
3506
|
+
Accept: "application/json",
|
|
3507
|
+
"X-API-Key": apiKey
|
|
3508
|
+
};
|
|
3486
3509
|
const res = yield fetch(`${apiBaseUrl}/api${path}`, {
|
|
3487
3510
|
method: "POST",
|
|
3488
|
-
headers
|
|
3489
|
-
"Content-Type": "application/json",
|
|
3490
|
-
Accept: "application/json",
|
|
3491
|
-
"X-API-Key": apiKey
|
|
3492
|
-
},
|
|
3511
|
+
headers,
|
|
3493
3512
|
body: JSON.stringify(body)
|
|
3494
3513
|
});
|
|
3495
3514
|
if (!res.ok) {
|
|
@@ -3500,13 +3519,17 @@ function useNotificationsActions() {
|
|
|
3500
3519
|
}
|
|
3501
3520
|
return yield res.json();
|
|
3502
3521
|
}),
|
|
3503
|
-
[apiBaseUrl, apiKey]
|
|
3522
|
+
[apiBaseUrl, apiKey, getAuthToken]
|
|
3504
3523
|
);
|
|
3505
3524
|
const get = (0, import_react6.useCallback)(
|
|
3506
|
-
(path) => __async(null, null, function* () {
|
|
3525
|
+
(path, opts) => __async(null, null, function* () {
|
|
3526
|
+
const headers = (opts == null ? void 0 : opts.requireUserToken) ? yield buildAuthHeaders(
|
|
3527
|
+
{ apiKey, getAuthToken },
|
|
3528
|
+
{ requireUserToken: true }
|
|
3529
|
+
) : { Accept: "application/json", "X-API-Key": apiKey };
|
|
3507
3530
|
const res = yield fetch(`${apiBaseUrl}/api${path}`, {
|
|
3508
3531
|
method: "GET",
|
|
3509
|
-
headers
|
|
3532
|
+
headers
|
|
3510
3533
|
});
|
|
3511
3534
|
if (!res.ok) {
|
|
3512
3535
|
const text = yield res.text().catch(() => "");
|
|
@@ -3516,7 +3539,7 @@ function useNotificationsActions() {
|
|
|
3516
3539
|
}
|
|
3517
3540
|
return yield res.json();
|
|
3518
3541
|
}),
|
|
3519
|
-
[apiBaseUrl, apiKey]
|
|
3542
|
+
[apiBaseUrl, apiKey, getAuthToken]
|
|
3520
3543
|
);
|
|
3521
3544
|
const send = (0, import_react6.useCallback)(
|
|
3522
3545
|
(input) => post("/notifications/send", input),
|
|
@@ -3528,14 +3551,16 @@ function useNotificationsActions() {
|
|
|
3528
3551
|
);
|
|
3529
3552
|
const getPreferences = (0, import_react6.useCallback)(
|
|
3530
3553
|
(userId) => get(
|
|
3531
|
-
`/notifications/preferences/${encodeURIComponent(userId)}
|
|
3554
|
+
`/notifications/preferences/${encodeURIComponent(userId)}`,
|
|
3555
|
+
{ requireUserToken: true }
|
|
3532
3556
|
),
|
|
3533
3557
|
[get]
|
|
3534
3558
|
);
|
|
3535
3559
|
const updatePreferences = (0, import_react6.useCallback)(
|
|
3536
3560
|
(userId, prefs) => post(
|
|
3537
3561
|
`/notifications/preferences/${encodeURIComponent(userId)}`,
|
|
3538
|
-
prefs
|
|
3562
|
+
prefs,
|
|
3563
|
+
{ requireUserToken: true }
|
|
3539
3564
|
),
|
|
3540
3565
|
[post]
|
|
3541
3566
|
);
|
|
@@ -3785,6 +3810,7 @@ function useUserSync(input) {
|
|
|
3785
3810
|
const sdkContext = useTruthSdkContext();
|
|
3786
3811
|
const apiBaseUrl = (_b = (_a = input.apiBaseUrl) != null ? _a : sdkContext == null ? void 0 : sdkContext.apiBaseUrl) != null ? _b : "";
|
|
3787
3812
|
const apiKey = (_d = (_c = input.apiKey) != null ? _c : sdkContext == null ? void 0 : sdkContext.apiKey) != null ? _d : "";
|
|
3813
|
+
const getAuthToken = sdkContext == null ? void 0 : sdkContext.getAuthToken;
|
|
3788
3814
|
const [status, setStatus] = (0, import_react11.useState)("idle");
|
|
3789
3815
|
const [error, setError] = (0, import_react11.useState)(null);
|
|
3790
3816
|
const lastKeyRef = (0, import_react11.useRef)(null);
|
|
@@ -3798,12 +3824,13 @@ function useUserSync(input) {
|
|
|
3798
3824
|
setStatus("syncing");
|
|
3799
3825
|
setError(null);
|
|
3800
3826
|
try {
|
|
3827
|
+
const headers = yield buildAuthHeaders(
|
|
3828
|
+
{ apiKey, getAuthToken },
|
|
3829
|
+
{ json: true, requireUserToken: true }
|
|
3830
|
+
);
|
|
3801
3831
|
const res = yield fetch(`${apiBaseUrl}/api/users/sync`, {
|
|
3802
3832
|
method: "POST",
|
|
3803
|
-
headers
|
|
3804
|
-
"Content-Type": "application/json",
|
|
3805
|
-
"X-API-Key": apiKey
|
|
3806
|
-
},
|
|
3833
|
+
headers,
|
|
3807
3834
|
body: JSON.stringify({
|
|
3808
3835
|
userId: input.userId,
|
|
3809
3836
|
email: input.email,
|