perspectapi-ts-sdk 6.5.6 → 6.5.7
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/index.d.mts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +35 -10
- package/dist/index.mjs +35 -10
- package/package.json +1 -1
- package/src/client/base-client.ts +2 -1
- package/src/utils/http-client.ts +8 -0
- package/src/v2/client/base-v2-client.ts +2 -1
- package/src/v2/client/credits-client.ts +7 -2
- package/src/v2/client/site-users-client.ts +20 -2
- package/src/v2/client/subscriptions-client.ts +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1126,6 +1126,11 @@ declare class HttpClient {
|
|
|
1126
1126
|
* Update API key
|
|
1127
1127
|
*/
|
|
1128
1128
|
setApiKey(apiKey: string): void;
|
|
1129
|
+
/**
|
|
1130
|
+
* Whether this client currently has a site-user/admin bearer token attached.
|
|
1131
|
+
* Bearer-scoped GETs must not share cache entries across callers.
|
|
1132
|
+
*/
|
|
1133
|
+
hasBearerAuth(): boolean;
|
|
1129
1134
|
/**
|
|
1130
1135
|
* Remove authentication
|
|
1131
1136
|
*/
|
|
@@ -1969,13 +1974,14 @@ declare class SiteUsersV2Client extends BaseV2Client {
|
|
|
1969
1974
|
list(siteName: string, params?: V2SiteUserListParams): Promise<V2List<V2SiteUser>>;
|
|
1970
1975
|
listAutoPaginated(siteName: string, params?: Omit<V2SiteUserListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2SiteUser, void, unknown>;
|
|
1971
1976
|
get(siteName: string, id: string): Promise<V2SiteUser>;
|
|
1977
|
+
getProfileForUser(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2SiteUserProfile>;
|
|
1972
1978
|
update(siteName: string, id: string, data: V2SiteUserUpdateParams): Promise<V2SiteUser>;
|
|
1973
1979
|
/**
|
|
1974
1980
|
* Load the currently-authenticated site user's canonical record plus their
|
|
1975
1981
|
* profile KV map. Requires `client.setAuth(jwt)` to have been called with
|
|
1976
1982
|
* the token returned from `verifyOtp`.
|
|
1977
1983
|
*/
|
|
1978
|
-
getMe(siteName: string): Promise<V2SiteUserWithProfile>;
|
|
1984
|
+
getMe(siteName: string, cachePolicy?: CachePolicy): Promise<V2SiteUserWithProfile>;
|
|
1979
1985
|
/** Update the authenticated user's own fields. */
|
|
1980
1986
|
updateMe(siteName: string, data: V2SiteUserMeUpdateParams): Promise<V2SiteUser>;
|
|
1981
1987
|
/** Fetch the profile KV map as a dedicated `site_user_profile` envelope. */
|
|
@@ -2145,9 +2151,9 @@ declare class SubscriptionsV2Client extends BaseV2Client {
|
|
|
2145
2151
|
|
|
2146
2152
|
declare class CreditsV2Client extends BaseV2Client {
|
|
2147
2153
|
/** Get the current credit balance for the authenticated user. */
|
|
2148
|
-
getMyBalance(siteName: string): Promise<V2CreditBalance>;
|
|
2154
|
+
getMyBalance(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance>;
|
|
2149
2155
|
/** Get credit balance and transaction history for the authenticated user. */
|
|
2150
|
-
getMyCredits(siteName: string): Promise<V2CreditBalance>;
|
|
2156
|
+
getMyCredits(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance>;
|
|
2151
2157
|
/** Get the credit balance for a specific user (admin). */
|
|
2152
2158
|
getUserBalance(siteName: string, userId: string): Promise<V2CreditBalance>;
|
|
2153
2159
|
/** Grant credit to a specific user (admin). */
|
package/dist/index.d.ts
CHANGED
|
@@ -1126,6 +1126,11 @@ declare class HttpClient {
|
|
|
1126
1126
|
* Update API key
|
|
1127
1127
|
*/
|
|
1128
1128
|
setApiKey(apiKey: string): void;
|
|
1129
|
+
/**
|
|
1130
|
+
* Whether this client currently has a site-user/admin bearer token attached.
|
|
1131
|
+
* Bearer-scoped GETs must not share cache entries across callers.
|
|
1132
|
+
*/
|
|
1133
|
+
hasBearerAuth(): boolean;
|
|
1129
1134
|
/**
|
|
1130
1135
|
* Remove authentication
|
|
1131
1136
|
*/
|
|
@@ -1969,13 +1974,14 @@ declare class SiteUsersV2Client extends BaseV2Client {
|
|
|
1969
1974
|
list(siteName: string, params?: V2SiteUserListParams): Promise<V2List<V2SiteUser>>;
|
|
1970
1975
|
listAutoPaginated(siteName: string, params?: Omit<V2SiteUserListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2SiteUser, void, unknown>;
|
|
1971
1976
|
get(siteName: string, id: string): Promise<V2SiteUser>;
|
|
1977
|
+
getProfileForUser(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2SiteUserProfile>;
|
|
1972
1978
|
update(siteName: string, id: string, data: V2SiteUserUpdateParams): Promise<V2SiteUser>;
|
|
1973
1979
|
/**
|
|
1974
1980
|
* Load the currently-authenticated site user's canonical record plus their
|
|
1975
1981
|
* profile KV map. Requires `client.setAuth(jwt)` to have been called with
|
|
1976
1982
|
* the token returned from `verifyOtp`.
|
|
1977
1983
|
*/
|
|
1978
|
-
getMe(siteName: string): Promise<V2SiteUserWithProfile>;
|
|
1984
|
+
getMe(siteName: string, cachePolicy?: CachePolicy): Promise<V2SiteUserWithProfile>;
|
|
1979
1985
|
/** Update the authenticated user's own fields. */
|
|
1980
1986
|
updateMe(siteName: string, data: V2SiteUserMeUpdateParams): Promise<V2SiteUser>;
|
|
1981
1987
|
/** Fetch the profile KV map as a dedicated `site_user_profile` envelope. */
|
|
@@ -2145,9 +2151,9 @@ declare class SubscriptionsV2Client extends BaseV2Client {
|
|
|
2145
2151
|
|
|
2146
2152
|
declare class CreditsV2Client extends BaseV2Client {
|
|
2147
2153
|
/** Get the current credit balance for the authenticated user. */
|
|
2148
|
-
getMyBalance(siteName: string): Promise<V2CreditBalance>;
|
|
2154
|
+
getMyBalance(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance>;
|
|
2149
2155
|
/** Get credit balance and transaction history for the authenticated user. */
|
|
2150
|
-
getMyCredits(siteName: string): Promise<V2CreditBalance>;
|
|
2156
|
+
getMyCredits(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance>;
|
|
2151
2157
|
/** Get the credit balance for a specific user (admin). */
|
|
2152
2158
|
getUserBalance(siteName: string, userId: string): Promise<V2CreditBalance>;
|
|
2153
2159
|
/** Grant credit to a specific user (admin). */
|
package/dist/index.js
CHANGED
|
@@ -132,6 +132,13 @@ var HttpClient = class {
|
|
|
132
132
|
setApiKey(apiKey) {
|
|
133
133
|
this.defaultHeaders["X-API-Key"] = apiKey;
|
|
134
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Whether this client currently has a site-user/admin bearer token attached.
|
|
137
|
+
* Bearer-scoped GETs must not share cache entries across callers.
|
|
138
|
+
*/
|
|
139
|
+
hasBearerAuth() {
|
|
140
|
+
return Boolean(this.defaultHeaders["Authorization"]);
|
|
141
|
+
}
|
|
135
142
|
/**
|
|
136
143
|
* Remove authentication
|
|
137
144
|
*/
|
|
@@ -684,7 +691,8 @@ var BaseV2Client = class {
|
|
|
684
691
|
}
|
|
685
692
|
/** Fetch with optional cache. Bypasses cache for writes or when no cache is configured. */
|
|
686
693
|
async fetchWithCache(path, params, policy, fetcher) {
|
|
687
|
-
|
|
694
|
+
const hasBearerAuth = typeof this.http.hasBearerAuth === "function" && this.http.hasBearerAuth();
|
|
695
|
+
if (!this.cache || policy?.skipCache || hasBearerAuth) {
|
|
688
696
|
return fetcher();
|
|
689
697
|
}
|
|
690
698
|
const key = this.buildCacheKey(path, params);
|
|
@@ -1001,6 +1009,9 @@ var OrdersV2Client = class extends BaseV2Client {
|
|
|
1001
1009
|
};
|
|
1002
1010
|
|
|
1003
1011
|
// src/v2/client/site-users-client.ts
|
|
1012
|
+
function bypassAuthenticatedCache(policy) {
|
|
1013
|
+
return { ...policy, skipCache: true };
|
|
1014
|
+
}
|
|
1004
1015
|
var SiteUsersV2Client = class extends BaseV2Client {
|
|
1005
1016
|
// --- OTP Auth (public, API-key-scoped) ---
|
|
1006
1017
|
async requestOtp(siteName, data) {
|
|
@@ -1019,6 +1030,13 @@ var SiteUsersV2Client = class extends BaseV2Client {
|
|
|
1019
1030
|
async get(siteName, id) {
|
|
1020
1031
|
return this.getOne(this.sitePath(siteName, "users", id));
|
|
1021
1032
|
}
|
|
1033
|
+
async getProfileForUser(siteName, id, cachePolicy) {
|
|
1034
|
+
return this.getOne(
|
|
1035
|
+
this.sitePath(siteName, "users", `${id}/profile`),
|
|
1036
|
+
void 0,
|
|
1037
|
+
cachePolicy
|
|
1038
|
+
);
|
|
1039
|
+
}
|
|
1022
1040
|
async update(siteName, id, data) {
|
|
1023
1041
|
return this.patchOne(this.sitePath(siteName, "users", id), data);
|
|
1024
1042
|
}
|
|
@@ -1028,9 +1046,11 @@ var SiteUsersV2Client = class extends BaseV2Client {
|
|
|
1028
1046
|
* profile KV map. Requires `client.setAuth(jwt)` to have been called with
|
|
1029
1047
|
* the token returned from `verifyOtp`.
|
|
1030
1048
|
*/
|
|
1031
|
-
async getMe(siteName) {
|
|
1049
|
+
async getMe(siteName, cachePolicy) {
|
|
1032
1050
|
return this.getOne(
|
|
1033
|
-
this.sitePath(siteName, "users", "me")
|
|
1051
|
+
this.sitePath(siteName, "users", "me"),
|
|
1052
|
+
void 0,
|
|
1053
|
+
bypassAuthenticatedCache(cachePolicy)
|
|
1034
1054
|
);
|
|
1035
1055
|
}
|
|
1036
1056
|
/** Update the authenticated user's own fields. */
|
|
@@ -1045,7 +1065,7 @@ var SiteUsersV2Client = class extends BaseV2Client {
|
|
|
1045
1065
|
return this.getOne(
|
|
1046
1066
|
this.sitePath(siteName, "users", "me/profile"),
|
|
1047
1067
|
void 0,
|
|
1048
|
-
cachePolicy
|
|
1068
|
+
bypassAuthenticatedCache(cachePolicy)
|
|
1049
1069
|
);
|
|
1050
1070
|
}
|
|
1051
1071
|
/**
|
|
@@ -1267,7 +1287,7 @@ var SubscriptionsV2Client = class extends BaseV2Client {
|
|
|
1267
1287
|
return this.getList(
|
|
1268
1288
|
this.sitePath(siteName, "users", "me/subscriptions"),
|
|
1269
1289
|
void 0,
|
|
1270
|
-
cachePolicy
|
|
1290
|
+
{ ...cachePolicy, skipCache: true }
|
|
1271
1291
|
);
|
|
1272
1292
|
}
|
|
1273
1293
|
/** Pause a subscription. */
|
|
@@ -1332,15 +1352,19 @@ var SubscriptionsV2Client = class extends BaseV2Client {
|
|
|
1332
1352
|
var CreditsV2Client = class extends BaseV2Client {
|
|
1333
1353
|
// --- Authenticated "me" endpoints (site-user JWT) ---
|
|
1334
1354
|
/** Get the current credit balance for the authenticated user. */
|
|
1335
|
-
async getMyBalance(siteName) {
|
|
1355
|
+
async getMyBalance(siteName, cachePolicy) {
|
|
1336
1356
|
return this.getOne(
|
|
1337
|
-
this.sitePath(siteName, "users", "me/credits/balance")
|
|
1357
|
+
this.sitePath(siteName, "users", "me/credits/balance"),
|
|
1358
|
+
void 0,
|
|
1359
|
+
{ ...cachePolicy, skipCache: true }
|
|
1338
1360
|
);
|
|
1339
1361
|
}
|
|
1340
1362
|
/** Get credit balance and transaction history for the authenticated user. */
|
|
1341
|
-
async getMyCredits(siteName) {
|
|
1363
|
+
async getMyCredits(siteName, cachePolicy) {
|
|
1342
1364
|
return this.getOne(
|
|
1343
|
-
this.sitePath(siteName, "users", "me/credits")
|
|
1365
|
+
this.sitePath(siteName, "users", "me/credits"),
|
|
1366
|
+
void 0,
|
|
1367
|
+
{ ...cachePolicy, skipCache: true }
|
|
1344
1368
|
);
|
|
1345
1369
|
}
|
|
1346
1370
|
// --- Admin endpoints (API key) ---
|
|
@@ -1488,7 +1512,8 @@ var BaseClient = class {
|
|
|
1488
1512
|
* Fetch a GET endpoint with optional caching support.
|
|
1489
1513
|
*/
|
|
1490
1514
|
async fetchWithCache(endpoint, params, tags, policy, fetcher) {
|
|
1491
|
-
|
|
1515
|
+
const hasBearerAuth = typeof this.http.hasBearerAuth === "function" && this.http.hasBearerAuth();
|
|
1516
|
+
if (!this.cache || hasBearerAuth) {
|
|
1492
1517
|
return fetcher();
|
|
1493
1518
|
}
|
|
1494
1519
|
const cacheKey = this.buildCacheKey(endpoint, params);
|
package/dist/index.mjs
CHANGED
|
@@ -56,6 +56,13 @@ var HttpClient = class {
|
|
|
56
56
|
setApiKey(apiKey) {
|
|
57
57
|
this.defaultHeaders["X-API-Key"] = apiKey;
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether this client currently has a site-user/admin bearer token attached.
|
|
61
|
+
* Bearer-scoped GETs must not share cache entries across callers.
|
|
62
|
+
*/
|
|
63
|
+
hasBearerAuth() {
|
|
64
|
+
return Boolean(this.defaultHeaders["Authorization"]);
|
|
65
|
+
}
|
|
59
66
|
/**
|
|
60
67
|
* Remove authentication
|
|
61
68
|
*/
|
|
@@ -608,7 +615,8 @@ var BaseV2Client = class {
|
|
|
608
615
|
}
|
|
609
616
|
/** Fetch with optional cache. Bypasses cache for writes or when no cache is configured. */
|
|
610
617
|
async fetchWithCache(path, params, policy, fetcher) {
|
|
611
|
-
|
|
618
|
+
const hasBearerAuth = typeof this.http.hasBearerAuth === "function" && this.http.hasBearerAuth();
|
|
619
|
+
if (!this.cache || policy?.skipCache || hasBearerAuth) {
|
|
612
620
|
return fetcher();
|
|
613
621
|
}
|
|
614
622
|
const key = this.buildCacheKey(path, params);
|
|
@@ -925,6 +933,9 @@ var OrdersV2Client = class extends BaseV2Client {
|
|
|
925
933
|
};
|
|
926
934
|
|
|
927
935
|
// src/v2/client/site-users-client.ts
|
|
936
|
+
function bypassAuthenticatedCache(policy) {
|
|
937
|
+
return { ...policy, skipCache: true };
|
|
938
|
+
}
|
|
928
939
|
var SiteUsersV2Client = class extends BaseV2Client {
|
|
929
940
|
// --- OTP Auth (public, API-key-scoped) ---
|
|
930
941
|
async requestOtp(siteName, data) {
|
|
@@ -943,6 +954,13 @@ var SiteUsersV2Client = class extends BaseV2Client {
|
|
|
943
954
|
async get(siteName, id) {
|
|
944
955
|
return this.getOne(this.sitePath(siteName, "users", id));
|
|
945
956
|
}
|
|
957
|
+
async getProfileForUser(siteName, id, cachePolicy) {
|
|
958
|
+
return this.getOne(
|
|
959
|
+
this.sitePath(siteName, "users", `${id}/profile`),
|
|
960
|
+
void 0,
|
|
961
|
+
cachePolicy
|
|
962
|
+
);
|
|
963
|
+
}
|
|
946
964
|
async update(siteName, id, data) {
|
|
947
965
|
return this.patchOne(this.sitePath(siteName, "users", id), data);
|
|
948
966
|
}
|
|
@@ -952,9 +970,11 @@ var SiteUsersV2Client = class extends BaseV2Client {
|
|
|
952
970
|
* profile KV map. Requires `client.setAuth(jwt)` to have been called with
|
|
953
971
|
* the token returned from `verifyOtp`.
|
|
954
972
|
*/
|
|
955
|
-
async getMe(siteName) {
|
|
973
|
+
async getMe(siteName, cachePolicy) {
|
|
956
974
|
return this.getOne(
|
|
957
|
-
this.sitePath(siteName, "users", "me")
|
|
975
|
+
this.sitePath(siteName, "users", "me"),
|
|
976
|
+
void 0,
|
|
977
|
+
bypassAuthenticatedCache(cachePolicy)
|
|
958
978
|
);
|
|
959
979
|
}
|
|
960
980
|
/** Update the authenticated user's own fields. */
|
|
@@ -969,7 +989,7 @@ var SiteUsersV2Client = class extends BaseV2Client {
|
|
|
969
989
|
return this.getOne(
|
|
970
990
|
this.sitePath(siteName, "users", "me/profile"),
|
|
971
991
|
void 0,
|
|
972
|
-
cachePolicy
|
|
992
|
+
bypassAuthenticatedCache(cachePolicy)
|
|
973
993
|
);
|
|
974
994
|
}
|
|
975
995
|
/**
|
|
@@ -1191,7 +1211,7 @@ var SubscriptionsV2Client = class extends BaseV2Client {
|
|
|
1191
1211
|
return this.getList(
|
|
1192
1212
|
this.sitePath(siteName, "users", "me/subscriptions"),
|
|
1193
1213
|
void 0,
|
|
1194
|
-
cachePolicy
|
|
1214
|
+
{ ...cachePolicy, skipCache: true }
|
|
1195
1215
|
);
|
|
1196
1216
|
}
|
|
1197
1217
|
/** Pause a subscription. */
|
|
@@ -1256,15 +1276,19 @@ var SubscriptionsV2Client = class extends BaseV2Client {
|
|
|
1256
1276
|
var CreditsV2Client = class extends BaseV2Client {
|
|
1257
1277
|
// --- Authenticated "me" endpoints (site-user JWT) ---
|
|
1258
1278
|
/** Get the current credit balance for the authenticated user. */
|
|
1259
|
-
async getMyBalance(siteName) {
|
|
1279
|
+
async getMyBalance(siteName, cachePolicy) {
|
|
1260
1280
|
return this.getOne(
|
|
1261
|
-
this.sitePath(siteName, "users", "me/credits/balance")
|
|
1281
|
+
this.sitePath(siteName, "users", "me/credits/balance"),
|
|
1282
|
+
void 0,
|
|
1283
|
+
{ ...cachePolicy, skipCache: true }
|
|
1262
1284
|
);
|
|
1263
1285
|
}
|
|
1264
1286
|
/** Get credit balance and transaction history for the authenticated user. */
|
|
1265
|
-
async getMyCredits(siteName) {
|
|
1287
|
+
async getMyCredits(siteName, cachePolicy) {
|
|
1266
1288
|
return this.getOne(
|
|
1267
|
-
this.sitePath(siteName, "users", "me/credits")
|
|
1289
|
+
this.sitePath(siteName, "users", "me/credits"),
|
|
1290
|
+
void 0,
|
|
1291
|
+
{ ...cachePolicy, skipCache: true }
|
|
1268
1292
|
);
|
|
1269
1293
|
}
|
|
1270
1294
|
// --- Admin endpoints (API key) ---
|
|
@@ -1412,7 +1436,8 @@ var BaseClient = class {
|
|
|
1412
1436
|
* Fetch a GET endpoint with optional caching support.
|
|
1413
1437
|
*/
|
|
1414
1438
|
async fetchWithCache(endpoint, params, tags, policy, fetcher) {
|
|
1415
|
-
|
|
1439
|
+
const hasBearerAuth = typeof this.http.hasBearerAuth === "function" && this.http.hasBearerAuth();
|
|
1440
|
+
if (!this.cache || hasBearerAuth) {
|
|
1416
1441
|
return fetcher();
|
|
1417
1442
|
}
|
|
1418
1443
|
const cacheKey = this.buildCacheKey(endpoint, params);
|
package/package.json
CHANGED
|
@@ -115,7 +115,8 @@ export abstract class BaseClient {
|
|
|
115
115
|
policy: CachePolicy | undefined,
|
|
116
116
|
fetcher: () => Promise<T>
|
|
117
117
|
): Promise<T> {
|
|
118
|
-
|
|
118
|
+
const hasBearerAuth = typeof this.http.hasBearerAuth === 'function' && this.http.hasBearerAuth();
|
|
119
|
+
if (!this.cache || hasBearerAuth) {
|
|
119
120
|
return fetcher();
|
|
120
121
|
}
|
|
121
122
|
|
package/src/utils/http-client.ts
CHANGED
|
@@ -51,6 +51,14 @@ export class HttpClient {
|
|
|
51
51
|
this.defaultHeaders['X-API-Key'] = apiKey;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Whether this client currently has a site-user/admin bearer token attached.
|
|
56
|
+
* Bearer-scoped GETs must not share cache entries across callers.
|
|
57
|
+
*/
|
|
58
|
+
hasBearerAuth(): boolean {
|
|
59
|
+
return Boolean(this.defaultHeaders['Authorization']);
|
|
60
|
+
}
|
|
61
|
+
|
|
54
62
|
/**
|
|
55
63
|
* Remove authentication
|
|
56
64
|
*/
|
|
@@ -148,7 +148,8 @@ export abstract class BaseV2Client {
|
|
|
148
148
|
policy: CachePolicy | undefined,
|
|
149
149
|
fetcher: () => Promise<T>,
|
|
150
150
|
): Promise<T> {
|
|
151
|
-
|
|
151
|
+
const hasBearerAuth = typeof this.http.hasBearerAuth === 'function' && this.http.hasBearerAuth();
|
|
152
|
+
if (!this.cache || policy?.skipCache || hasBearerAuth) {
|
|
152
153
|
return fetcher();
|
|
153
154
|
}
|
|
154
155
|
const key = this.buildCacheKey(path, params);
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { BaseV2Client } from './base-v2-client';
|
|
10
|
+
import type { CachePolicy } from '../../cache/types';
|
|
10
11
|
import type {
|
|
11
12
|
V2CreditBalance,
|
|
12
13
|
V2GrantCreditParams,
|
|
@@ -18,16 +19,20 @@ export class CreditsV2Client extends BaseV2Client {
|
|
|
18
19
|
// --- Authenticated "me" endpoints (site-user JWT) ---
|
|
19
20
|
|
|
20
21
|
/** Get the current credit balance for the authenticated user. */
|
|
21
|
-
async getMyBalance(siteName: string): Promise<V2CreditBalance> {
|
|
22
|
+
async getMyBalance(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance> {
|
|
22
23
|
return this.getOne<V2CreditBalance>(
|
|
23
24
|
this.sitePath(siteName, 'users', 'me/credits/balance'),
|
|
25
|
+
undefined,
|
|
26
|
+
{ ...cachePolicy, skipCache: true },
|
|
24
27
|
);
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
/** Get credit balance and transaction history for the authenticated user. */
|
|
28
|
-
async getMyCredits(siteName: string): Promise<V2CreditBalance> {
|
|
31
|
+
async getMyCredits(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance> {
|
|
29
32
|
return this.getOne<V2CreditBalance>(
|
|
30
33
|
this.sitePath(siteName, 'users', 'me/credits'),
|
|
34
|
+
undefined,
|
|
35
|
+
{ ...cachePolicy, skipCache: true },
|
|
31
36
|
);
|
|
32
37
|
}
|
|
33
38
|
|
|
@@ -31,6 +31,10 @@ export interface V2OtpVerifyResponse extends V2SiteUser {
|
|
|
31
31
|
token: string;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
function bypassAuthenticatedCache(policy?: CachePolicy): CachePolicy {
|
|
35
|
+
return { ...policy, skipCache: true };
|
|
36
|
+
}
|
|
37
|
+
|
|
34
38
|
export class SiteUsersV2Client extends BaseV2Client {
|
|
35
39
|
|
|
36
40
|
// --- OTP Auth (public, API-key-scoped) ---
|
|
@@ -63,6 +67,18 @@ export class SiteUsersV2Client extends BaseV2Client {
|
|
|
63
67
|
return this.getOne<V2SiteUser>(this.sitePath(siteName, 'users', id));
|
|
64
68
|
}
|
|
65
69
|
|
|
70
|
+
async getProfileForUser(
|
|
71
|
+
siteName: string,
|
|
72
|
+
id: string,
|
|
73
|
+
cachePolicy?: CachePolicy,
|
|
74
|
+
): Promise<V2SiteUserProfile> {
|
|
75
|
+
return this.getOne<V2SiteUserProfile>(
|
|
76
|
+
this.sitePath(siteName, 'users', `${id}/profile`),
|
|
77
|
+
undefined,
|
|
78
|
+
cachePolicy,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
66
82
|
async update(siteName: string, id: string, data: V2SiteUserUpdateParams): Promise<V2SiteUser> {
|
|
67
83
|
return this.patchOne<V2SiteUser>(this.sitePath(siteName, 'users', id), data);
|
|
68
84
|
}
|
|
@@ -74,9 +90,11 @@ export class SiteUsersV2Client extends BaseV2Client {
|
|
|
74
90
|
* profile KV map. Requires `client.setAuth(jwt)` to have been called with
|
|
75
91
|
* the token returned from `verifyOtp`.
|
|
76
92
|
*/
|
|
77
|
-
async getMe(siteName: string): Promise<V2SiteUserWithProfile> {
|
|
93
|
+
async getMe(siteName: string, cachePolicy?: CachePolicy): Promise<V2SiteUserWithProfile> {
|
|
78
94
|
return this.getOne<V2SiteUserWithProfile>(
|
|
79
95
|
this.sitePath(siteName, 'users', 'me'),
|
|
96
|
+
undefined,
|
|
97
|
+
bypassAuthenticatedCache(cachePolicy),
|
|
80
98
|
);
|
|
81
99
|
}
|
|
82
100
|
|
|
@@ -96,7 +114,7 @@ export class SiteUsersV2Client extends BaseV2Client {
|
|
|
96
114
|
return this.getOne<V2SiteUserProfile>(
|
|
97
115
|
this.sitePath(siteName, 'users', 'me/profile'),
|
|
98
116
|
undefined,
|
|
99
|
-
cachePolicy,
|
|
117
|
+
bypassAuthenticatedCache(cachePolicy),
|
|
100
118
|
);
|
|
101
119
|
}
|
|
102
120
|
|