@stackframe/react 2.8.41 → 2.8.44
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/CHANGELOG.md +29 -0
- package/dist/esm/integrations/convex/component/convex.config.js +8 -0
- package/dist/esm/integrations/convex/component/convex.config.js.map +1 -0
- package/dist/esm/integrations/convex.js +5 -4
- package/dist/esm/integrations/convex.js.map +1 -1
- package/dist/esm/lib/hooks.js +3 -0
- package/dist/esm/lib/hooks.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +31 -42
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +106 -31
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js +16 -2
- package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +119 -60
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/esm/lib/stack-app/projects/index.js.map +1 -1
- package/dist/esm/lib/stack-app/users/index.js +16 -0
- package/dist/esm/lib/stack-app/users/index.js.map +1 -1
- package/dist/esm/providers/stack-provider.js +2 -6
- package/dist/esm/providers/stack-provider.js.map +1 -1
- package/dist/index.d.mts +86 -23
- package/dist/index.d.ts +86 -23
- package/dist/integrations/convex/component/convex.config.d.mts +5 -0
- package/dist/integrations/convex/component/convex.config.d.ts +5 -0
- package/dist/integrations/convex/component/convex.config.js +29 -0
- package/dist/integrations/convex/component/convex.config.js.map +1 -0
- package/dist/integrations/convex.js +4 -3
- package/dist/integrations/convex.js.map +1 -1
- package/dist/lib/hooks.js +3 -0
- package/dist/lib/hooks.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +30 -41
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js +104 -29
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/common.js +17 -1
- package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js +117 -58
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/lib/stack-app/customers/index.js.map +1 -1
- package/dist/lib/stack-app/projects/index.js.map +1 -1
- package/dist/lib/stack-app/users/index.js +17 -0
- package/dist/lib/stack-app/users/index.js.map +1 -1
- package/dist/providers/stack-provider.js +1 -5
- package/dist/providers/stack-provider.js.map +1 -1
- package/package.json +16 -7
|
@@ -64,8 +64,7 @@ var isReactServer = false;
|
|
|
64
64
|
var process = globalThis.process ?? { env: {} };
|
|
65
65
|
var allClientApps = /* @__PURE__ */ new Map();
|
|
66
66
|
var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
67
|
-
constructor(
|
|
68
|
-
this._options = _options;
|
|
67
|
+
constructor(options, extraOptions) {
|
|
69
68
|
this._uniqueIdentifier = void 0;
|
|
70
69
|
this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY = false;
|
|
71
70
|
this._ownedAdminApps = new import_maps.DependenciesMap();
|
|
@@ -111,7 +110,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
111
110
|
return await this._getUserOAuthConnectionCacheFn({
|
|
112
111
|
getUser: async () => import_results.Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only")),
|
|
113
112
|
getOrWaitOAuthToken: async () => import_results.Result.orThrow(await this._currentUserOAuthConnectionAccessTokensCache.getOrWait([session, providerId, scope || ""], "write-only")),
|
|
114
|
-
useOAuthToken: () => (0, import_common3.useAsyncCache)(this._currentUserOAuthConnectionAccessTokensCache, [session, providerId, scope || ""], "
|
|
113
|
+
useOAuthToken: () => (0, import_common3.useAsyncCache)(this._currentUserOAuthConnectionAccessTokensCache, [session, providerId, scope || ""], "connection.useAccessToken()"),
|
|
115
114
|
providerId,
|
|
116
115
|
scope,
|
|
117
116
|
redirect,
|
|
@@ -177,6 +176,36 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
177
176
|
return await this._interface.getItem({ customCustomerId, itemId }, session);
|
|
178
177
|
}
|
|
179
178
|
);
|
|
179
|
+
this._userProductsCache = (0, import_common2.createCacheBySession)(
|
|
180
|
+
async (session, [userId, cursor, limit]) => {
|
|
181
|
+
return await this._interface.listProducts({
|
|
182
|
+
customer_type: "user",
|
|
183
|
+
customer_id: userId,
|
|
184
|
+
cursor: cursor ?? void 0,
|
|
185
|
+
limit: limit ?? void 0
|
|
186
|
+
}, session);
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
this._teamProductsCache = (0, import_common2.createCacheBySession)(
|
|
190
|
+
async (session, [teamId, cursor, limit]) => {
|
|
191
|
+
return await this._interface.listProducts({
|
|
192
|
+
customer_type: "team",
|
|
193
|
+
customer_id: teamId,
|
|
194
|
+
cursor: cursor ?? void 0,
|
|
195
|
+
limit: limit ?? void 0
|
|
196
|
+
}, session);
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
this._customProductsCache = (0, import_common2.createCacheBySession)(
|
|
200
|
+
async (session, [customCustomerId, cursor, limit]) => {
|
|
201
|
+
return await this._interface.listProducts({
|
|
202
|
+
customer_type: "custom",
|
|
203
|
+
customer_id: customCustomerId,
|
|
204
|
+
cursor: cursor ?? void 0,
|
|
205
|
+
limit: limit ?? void 0
|
|
206
|
+
}, session);
|
|
207
|
+
}
|
|
208
|
+
);
|
|
180
209
|
this._convexPartialUserCache = (0, import_common2.createCache)(
|
|
181
210
|
async ([ctx]) => await this._getPartialUserFromConvex(ctx)
|
|
182
211
|
);
|
|
@@ -194,28 +223,31 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
194
223
|
* - So different token stores are separated and don't leak information between each other, eg. if the same user sends two requests to the same server they should get a different session object
|
|
195
224
|
*/
|
|
196
225
|
this._sessionsByTokenStoreAndSessionKey = /* @__PURE__ */ new WeakMap();
|
|
226
|
+
const resolvedOptions = (0, import_common2.resolveConstructorOptions)(options);
|
|
197
227
|
if (!__StackClientAppImplIncomplete.LazyStackAdminAppImpl.value) {
|
|
198
228
|
throw new import_errors.StackAssertionError("Admin app implementation not initialized. Did you import the _StackClientApp from stack-app/apps/implementations/index.ts? You can't import it directly from ./apps/implementations/client-app-impl.ts as that causes a circular dependency (see the comment at _LazyStackAdminAppImpl for more details).");
|
|
199
229
|
}
|
|
200
|
-
|
|
201
|
-
|
|
230
|
+
this._options = resolvedOptions;
|
|
231
|
+
this._extraOptions = extraOptions;
|
|
232
|
+
if (extraOptions && extraOptions.interface) {
|
|
233
|
+
this._interface = extraOptions.interface;
|
|
202
234
|
} else {
|
|
203
235
|
this._interface = new import_stack_shared.StackClientInterface({
|
|
204
|
-
getBaseUrl: () => (0, import_common2.getBaseUrl)(
|
|
205
|
-
extraRequestHeaders:
|
|
206
|
-
projectId:
|
|
236
|
+
getBaseUrl: () => (0, import_common2.getBaseUrl)(resolvedOptions.baseUrl),
|
|
237
|
+
extraRequestHeaders: resolvedOptions.extraRequestHeaders ?? (0, import_common2.getDefaultExtraRequestHeaders)(),
|
|
238
|
+
projectId: resolvedOptions.projectId ?? (0, import_common2.getDefaultProjectId)(),
|
|
207
239
|
clientVersion: import_common2.clientVersion,
|
|
208
|
-
publishableClientKey:
|
|
240
|
+
publishableClientKey: resolvedOptions.publishableClientKey ?? (0, import_common2.getDefaultPublishableClientKey)(),
|
|
209
241
|
prepareRequest: async () => {
|
|
210
242
|
}
|
|
211
243
|
});
|
|
212
244
|
}
|
|
213
|
-
this._tokenStoreInit =
|
|
214
|
-
this._redirectMethod =
|
|
215
|
-
this._urlOptions =
|
|
216
|
-
this._oauthScopesOnSignIn =
|
|
217
|
-
if (
|
|
218
|
-
this._uniqueIdentifier =
|
|
245
|
+
this._tokenStoreInit = resolvedOptions.tokenStore;
|
|
246
|
+
this._redirectMethod = resolvedOptions.redirectMethod || "none";
|
|
247
|
+
this._urlOptions = resolvedOptions.urls ?? {};
|
|
248
|
+
this._oauthScopesOnSignIn = resolvedOptions.oauthScopesOnSignIn ?? {};
|
|
249
|
+
if (extraOptions && extraOptions.uniqueIdentifier) {
|
|
250
|
+
this._uniqueIdentifier = extraOptions.uniqueIdentifier;
|
|
219
251
|
this._initUniqueIdentifier();
|
|
220
252
|
}
|
|
221
253
|
}
|
|
@@ -283,7 +315,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
283
315
|
if (allClientApps.has(this._uniqueIdentifier)) {
|
|
284
316
|
throw new import_errors.StackAssertionError("A Stack client app with the same unique identifier already exists");
|
|
285
317
|
}
|
|
286
|
-
allClientApps.set(this._uniqueIdentifier, [this.
|
|
318
|
+
allClientApps.set(this._uniqueIdentifier, [this._extraOptions?.checkString ?? void 0, this]);
|
|
287
319
|
}
|
|
288
320
|
/**
|
|
289
321
|
* Cloudflare workers does not allow use of randomness on the global scope (on which the Stack app is probably
|
|
@@ -732,6 +764,17 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
732
764
|
nonNegativeQuantity: Math.max(0, crud.quantity)
|
|
733
765
|
};
|
|
734
766
|
}
|
|
767
|
+
_customerProductsFromResponse(response) {
|
|
768
|
+
const products = response.items.map((item) => ({
|
|
769
|
+
id: item.id,
|
|
770
|
+
quantity: item.quantity,
|
|
771
|
+
displayName: item.product.display_name,
|
|
772
|
+
customerType: item.product.customer_type,
|
|
773
|
+
isServerOnly: item.product.server_only,
|
|
774
|
+
stackable: item.product.stackable
|
|
775
|
+
}));
|
|
776
|
+
return Object.assign(products, { nextCursor: response.pagination.next_cursor ?? null });
|
|
777
|
+
}
|
|
735
778
|
_createAuth(session) {
|
|
736
779
|
const app = this;
|
|
737
780
|
return {
|
|
@@ -1041,6 +1084,10 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1041
1084
|
createProject(newProject) {
|
|
1042
1085
|
return app._createProject(session, newProject);
|
|
1043
1086
|
},
|
|
1087
|
+
async transferProject(projectIdToTransfer, newTeamId) {
|
|
1088
|
+
await app._interface.transferProject(session, projectIdToTransfer, newTeamId);
|
|
1089
|
+
await app._refreshProject();
|
|
1090
|
+
},
|
|
1044
1091
|
listOwnedProjects() {
|
|
1045
1092
|
return app._listOwnedProjects(session);
|
|
1046
1093
|
},
|
|
@@ -1051,18 +1098,22 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1051
1098
|
}
|
|
1052
1099
|
_createCustomer(userIdOrTeamId, type, session) {
|
|
1053
1100
|
const app = this;
|
|
1054
|
-
const
|
|
1101
|
+
const customerOptions = type === "user" ? { userId: userIdOrTeamId } : { teamId: userIdOrTeamId };
|
|
1055
1102
|
return {
|
|
1056
1103
|
async getItem(itemId) {
|
|
1057
|
-
|
|
1058
|
-
return app._clientItemFromCrud(result);
|
|
1104
|
+
return await app.getItem({ itemId, ...customerOptions });
|
|
1059
1105
|
},
|
|
1060
1106
|
useItem(itemId) {
|
|
1061
|
-
|
|
1062
|
-
|
|
1107
|
+
return app.useItem({ itemId, ...customerOptions });
|
|
1108
|
+
},
|
|
1109
|
+
async listProducts(options) {
|
|
1110
|
+
return await app.listProducts({ ...options, ...customerOptions });
|
|
1111
|
+
},
|
|
1112
|
+
useProducts(options) {
|
|
1113
|
+
return app.useProducts({ ...options, ...customerOptions });
|
|
1063
1114
|
},
|
|
1064
1115
|
async createCheckoutUrl(options) {
|
|
1065
|
-
return await app._interface.createCheckoutUrl(type, userIdOrTeamId, options.
|
|
1116
|
+
return await app._interface.createCheckoutUrl(type, userIdOrTeamId, options.productId, session, options.returnUrl);
|
|
1066
1117
|
}
|
|
1067
1118
|
};
|
|
1068
1119
|
}
|
|
@@ -1084,6 +1135,26 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1084
1135
|
const crud = (0, import_common3.useAsyncCache)(cache, [session, ownerId, options.itemId], "app.useItem()");
|
|
1085
1136
|
return this._clientItemFromCrud(crud);
|
|
1086
1137
|
}
|
|
1138
|
+
async listProducts(options) {
|
|
1139
|
+
const session = await this._getSession();
|
|
1140
|
+
if ("userId" in options) {
|
|
1141
|
+
const response2 = import_results.Result.orThrow(await this._userProductsCache.getOrWait([session, options.userId, options.cursor ?? null, options.limit ?? null], "write-only"));
|
|
1142
|
+
return this._customerProductsFromResponse(response2);
|
|
1143
|
+
} else if ("teamId" in options) {
|
|
1144
|
+
const response2 = import_results.Result.orThrow(await this._teamProductsCache.getOrWait([session, options.teamId, options.cursor ?? null, options.limit ?? null], "write-only"));
|
|
1145
|
+
return this._customerProductsFromResponse(response2);
|
|
1146
|
+
}
|
|
1147
|
+
const response = import_results.Result.orThrow(await this._customProductsCache.getOrWait([session, options.customCustomerId, options.cursor ?? null, options.limit ?? null], "write-only"));
|
|
1148
|
+
return this._customerProductsFromResponse(response);
|
|
1149
|
+
}
|
|
1150
|
+
useProducts(options) {
|
|
1151
|
+
const session = this._useSession();
|
|
1152
|
+
const cache = "userId" in options ? this._userProductsCache : "teamId" in options ? this._teamProductsCache : this._customProductsCache;
|
|
1153
|
+
const debugLabel = "clientApp.useProducts()";
|
|
1154
|
+
const customerId = "userId" in options ? options.userId : "teamId" in options ? options.teamId : options.customCustomerId;
|
|
1155
|
+
const response = (0, import_common3.useAsyncCache)(cache, [session, customerId, options.cursor ?? null, options.limit ?? null], debugLabel);
|
|
1156
|
+
return this._customerProductsFromResponse(response);
|
|
1157
|
+
}
|
|
1087
1158
|
_currentUserFromCrud(crud, session) {
|
|
1088
1159
|
const currentUser = {
|
|
1089
1160
|
...this._createBaseUser(crud),
|
|
@@ -1092,6 +1163,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1092
1163
|
...this._isInternalProject() ? this._createInternalUserExtra(session) : {},
|
|
1093
1164
|
...this._createCustomer(crud.id, "user", session)
|
|
1094
1165
|
};
|
|
1166
|
+
(0, import_users.attachUserDestructureGuard)(currentUser);
|
|
1095
1167
|
Object.freeze(currentUser);
|
|
1096
1168
|
return currentUser;
|
|
1097
1169
|
}
|
|
@@ -1320,7 +1392,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1320
1392
|
useUser(options) {
|
|
1321
1393
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1322
1394
|
const session = this._useSession(options?.tokenStore);
|
|
1323
|
-
let crud = (0, import_common3.useAsyncCache)(this._currentUserCache, [session], "useUser()");
|
|
1395
|
+
let crud = (0, import_common3.useAsyncCache)(this._currentUserCache, [session], "clientApp.useUser()");
|
|
1324
1396
|
if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists[deprecated]") {
|
|
1325
1397
|
crud = null;
|
|
1326
1398
|
}
|
|
@@ -1407,7 +1479,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1407
1479
|
return this._getTokenPartialUserFromSession(session, options);
|
|
1408
1480
|
}
|
|
1409
1481
|
case "convex": {
|
|
1410
|
-
const result = (0, import_common3.useAsyncCache)(this._convexPartialUserCache, [options.ctx], "usePartialUser(
|
|
1482
|
+
const result = (0, import_common3.useAsyncCache)(this._convexPartialUserCache, [options.ctx], "clientApp.usePartialUser()");
|
|
1411
1483
|
return result;
|
|
1412
1484
|
}
|
|
1413
1485
|
default: {
|
|
@@ -1417,7 +1489,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1417
1489
|
}
|
|
1418
1490
|
getConvexClientAuth(options) {
|
|
1419
1491
|
return async (args) => {
|
|
1420
|
-
const session = await this._getSession(options.tokenStore);
|
|
1492
|
+
const session = await this._getSession(options.tokenStore ?? this._tokenStoreInit);
|
|
1421
1493
|
if (!args.forceRefreshToken) {
|
|
1422
1494
|
const tokens2 = await session.getOrFetchLikelyValidTokens(2e4);
|
|
1423
1495
|
return tokens2?.accessToken.token ?? null;
|
|
@@ -1429,7 +1501,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1429
1501
|
async getConvexHttpClientAuth(options) {
|
|
1430
1502
|
const session = await this._getSession(options.tokenStore);
|
|
1431
1503
|
const tokens = await session.getOrFetchLikelyValidTokens(2e4);
|
|
1432
|
-
return tokens?.accessToken.token ??
|
|
1504
|
+
return tokens?.accessToken.token ?? "";
|
|
1433
1505
|
}
|
|
1434
1506
|
async _updateClientUser(update, session) {
|
|
1435
1507
|
const res = await this._interface.updateClientUser((0, import_users.userUpdateOptionsToCrud)(update), session);
|
|
@@ -1767,7 +1839,7 @@ ${url}`);
|
|
|
1767
1839
|
return this._clientProjectFromCrud(crud);
|
|
1768
1840
|
}
|
|
1769
1841
|
useProject() {
|
|
1770
|
-
const crud = (0, import_common3.useAsyncCache)(this._currentProjectCache, [], "useProject()");
|
|
1842
|
+
const crud = (0, import_common3.useAsyncCache)(this._currentProjectCache, [], "clientApp.useProject()");
|
|
1771
1843
|
return (0, import_react2.useMemo)(() => this._clientProjectFromCrud(crud), [crud]);
|
|
1772
1844
|
}
|
|
1773
1845
|
async _listOwnedProjects(session) {
|
|
@@ -1780,7 +1852,7 @@ ${url}`);
|
|
|
1780
1852
|
}
|
|
1781
1853
|
_useOwnedProjects(session) {
|
|
1782
1854
|
this._ensureInternalProject();
|
|
1783
|
-
const projects = (0, import_common3.useAsyncCache)(this._ownedProjectsCache, [session], "useOwnedProjects()");
|
|
1855
|
+
const projects = (0, import_common3.useAsyncCache)(this._ownedProjectsCache, [session], "clientApp.useOwnedProjects()");
|
|
1784
1856
|
return (0, import_react2.useMemo)(() => projects.map((j) => this._getOwnedAdminApp(j.id, session)._adminOwnedProjectFromCrud(
|
|
1785
1857
|
j,
|
|
1786
1858
|
() => this._refreshOwnedProjects(session)
|
|
@@ -1825,7 +1897,9 @@ ${url}`);
|
|
|
1825
1897
|
return clientApp;
|
|
1826
1898
|
}
|
|
1827
1899
|
return new __StackClientAppImplIncomplete({
|
|
1828
|
-
...json,
|
|
1900
|
+
...(0, import_objects.omit)(json, ["uniqueIdentifier"])
|
|
1901
|
+
}, {
|
|
1902
|
+
uniqueIdentifier: json.uniqueIdentifier,
|
|
1829
1903
|
checkString: providedCheckString
|
|
1830
1904
|
});
|
|
1831
1905
|
}
|
|
@@ -1857,6 +1931,7 @@ ${url}`);
|
|
|
1857
1931
|
await this._currentUserCache.forceSetCachedValueAsync([await this._getSession()], import_results.Result.fromPromise(userJsonPromise));
|
|
1858
1932
|
});
|
|
1859
1933
|
},
|
|
1934
|
+
getConstructorOptions: () => this._options,
|
|
1860
1935
|
sendRequest: async (path, requestOptions, requestType = "client") => {
|
|
1861
1936
|
return await this._interface.sendClientRequest(path, requestOptions, await this._getSession(), requestType);
|
|
1862
1937
|
}
|