@stackframe/stack 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 +107 -32
- 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 +105 -30
- 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 +19 -10
|
@@ -69,8 +69,7 @@ isReactServer2 = sc.isReactServer;
|
|
|
69
69
|
var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
|
|
70
70
|
var allClientApps = /* @__PURE__ */ new Map();
|
|
71
71
|
var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
72
|
-
constructor(
|
|
73
|
-
this._options = _options;
|
|
72
|
+
constructor(options, extraOptions) {
|
|
74
73
|
this._uniqueIdentifier = void 0;
|
|
75
74
|
this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY = false;
|
|
76
75
|
this._ownedAdminApps = new import_maps.DependenciesMap();
|
|
@@ -116,7 +115,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
116
115
|
return await this._getUserOAuthConnectionCacheFn({
|
|
117
116
|
getUser: async () => import_results.Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only")),
|
|
118
117
|
getOrWaitOAuthToken: async () => import_results.Result.orThrow(await this._currentUserOAuthConnectionAccessTokensCache.getOrWait([session, providerId, scope || ""], "write-only")),
|
|
119
|
-
useOAuthToken: () => (0, import_common3.useAsyncCache)(this._currentUserOAuthConnectionAccessTokensCache, [session, providerId, scope || ""], "
|
|
118
|
+
useOAuthToken: () => (0, import_common3.useAsyncCache)(this._currentUserOAuthConnectionAccessTokensCache, [session, providerId, scope || ""], "connection.useAccessToken()"),
|
|
120
119
|
providerId,
|
|
121
120
|
scope,
|
|
122
121
|
redirect,
|
|
@@ -182,6 +181,36 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
182
181
|
return await this._interface.getItem({ customCustomerId, itemId }, session);
|
|
183
182
|
}
|
|
184
183
|
);
|
|
184
|
+
this._userProductsCache = (0, import_common2.createCacheBySession)(
|
|
185
|
+
async (session, [userId, cursor, limit]) => {
|
|
186
|
+
return await this._interface.listProducts({
|
|
187
|
+
customer_type: "user",
|
|
188
|
+
customer_id: userId,
|
|
189
|
+
cursor: cursor ?? void 0,
|
|
190
|
+
limit: limit ?? void 0
|
|
191
|
+
}, session);
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
this._teamProductsCache = (0, import_common2.createCacheBySession)(
|
|
195
|
+
async (session, [teamId, cursor, limit]) => {
|
|
196
|
+
return await this._interface.listProducts({
|
|
197
|
+
customer_type: "team",
|
|
198
|
+
customer_id: teamId,
|
|
199
|
+
cursor: cursor ?? void 0,
|
|
200
|
+
limit: limit ?? void 0
|
|
201
|
+
}, session);
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
this._customProductsCache = (0, import_common2.createCacheBySession)(
|
|
205
|
+
async (session, [customCustomerId, cursor, limit]) => {
|
|
206
|
+
return await this._interface.listProducts({
|
|
207
|
+
customer_type: "custom",
|
|
208
|
+
customer_id: customCustomerId,
|
|
209
|
+
cursor: cursor ?? void 0,
|
|
210
|
+
limit: limit ?? void 0
|
|
211
|
+
}, session);
|
|
212
|
+
}
|
|
213
|
+
);
|
|
185
214
|
this._convexPartialUserCache = (0, import_common2.createCache)(
|
|
186
215
|
async ([ctx]) => await this._getPartialUserFromConvex(ctx)
|
|
187
216
|
);
|
|
@@ -199,30 +228,33 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
199
228
|
* - 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
|
|
200
229
|
*/
|
|
201
230
|
this._sessionsByTokenStoreAndSessionKey = /* @__PURE__ */ new WeakMap();
|
|
231
|
+
const resolvedOptions = (0, import_common2.resolveConstructorOptions)(options);
|
|
202
232
|
if (!__StackClientAppImplIncomplete.LazyStackAdminAppImpl.value) {
|
|
203
233
|
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).");
|
|
204
234
|
}
|
|
205
|
-
|
|
206
|
-
|
|
235
|
+
this._options = resolvedOptions;
|
|
236
|
+
this._extraOptions = extraOptions;
|
|
237
|
+
if (extraOptions && extraOptions.interface) {
|
|
238
|
+
this._interface = extraOptions.interface;
|
|
207
239
|
} else {
|
|
208
240
|
this._interface = new import_stack_shared.StackClientInterface({
|
|
209
|
-
getBaseUrl: () => (0, import_common2.getBaseUrl)(
|
|
210
|
-
extraRequestHeaders:
|
|
211
|
-
projectId:
|
|
241
|
+
getBaseUrl: () => (0, import_common2.getBaseUrl)(resolvedOptions.baseUrl),
|
|
242
|
+
extraRequestHeaders: resolvedOptions.extraRequestHeaders ?? (0, import_common2.getDefaultExtraRequestHeaders)(),
|
|
243
|
+
projectId: resolvedOptions.projectId ?? (0, import_common2.getDefaultProjectId)(),
|
|
212
244
|
clientVersion: import_common2.clientVersion,
|
|
213
|
-
publishableClientKey:
|
|
245
|
+
publishableClientKey: resolvedOptions.publishableClientKey ?? (0, import_common2.getDefaultPublishableClientKey)(),
|
|
214
246
|
prepareRequest: async () => {
|
|
215
247
|
await (0, import_stack_sc.cookies)?.();
|
|
216
248
|
}
|
|
217
249
|
});
|
|
218
250
|
}
|
|
219
|
-
this._tokenStoreInit =
|
|
220
|
-
this._redirectMethod =
|
|
221
|
-
this._redirectMethod =
|
|
222
|
-
this._urlOptions =
|
|
223
|
-
this._oauthScopesOnSignIn =
|
|
224
|
-
if (
|
|
225
|
-
this._uniqueIdentifier =
|
|
251
|
+
this._tokenStoreInit = resolvedOptions.tokenStore;
|
|
252
|
+
this._redirectMethod = resolvedOptions.redirectMethod || "none";
|
|
253
|
+
this._redirectMethod = resolvedOptions.redirectMethod || "nextjs";
|
|
254
|
+
this._urlOptions = resolvedOptions.urls ?? {};
|
|
255
|
+
this._oauthScopesOnSignIn = resolvedOptions.oauthScopesOnSignIn ?? {};
|
|
256
|
+
if (extraOptions && extraOptions.uniqueIdentifier) {
|
|
257
|
+
this._uniqueIdentifier = extraOptions.uniqueIdentifier;
|
|
226
258
|
this._initUniqueIdentifier();
|
|
227
259
|
}
|
|
228
260
|
}
|
|
@@ -290,7 +322,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
290
322
|
if (allClientApps.has(this._uniqueIdentifier)) {
|
|
291
323
|
throw new import_errors.StackAssertionError("A Stack client app with the same unique identifier already exists");
|
|
292
324
|
}
|
|
293
|
-
allClientApps.set(this._uniqueIdentifier, [this.
|
|
325
|
+
allClientApps.set(this._uniqueIdentifier, [this._extraOptions?.checkString ?? void 0, this]);
|
|
294
326
|
}
|
|
295
327
|
/**
|
|
296
328
|
* Cloudflare workers does not allow use of randomness on the global scope (on which the Stack app is probably
|
|
@@ -739,6 +771,17 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
739
771
|
nonNegativeQuantity: Math.max(0, crud.quantity)
|
|
740
772
|
};
|
|
741
773
|
}
|
|
774
|
+
_customerProductsFromResponse(response) {
|
|
775
|
+
const products = response.items.map((item) => ({
|
|
776
|
+
id: item.id,
|
|
777
|
+
quantity: item.quantity,
|
|
778
|
+
displayName: item.product.display_name,
|
|
779
|
+
customerType: item.product.customer_type,
|
|
780
|
+
isServerOnly: item.product.server_only,
|
|
781
|
+
stackable: item.product.stackable
|
|
782
|
+
}));
|
|
783
|
+
return Object.assign(products, { nextCursor: response.pagination.next_cursor ?? null });
|
|
784
|
+
}
|
|
742
785
|
_createAuth(session) {
|
|
743
786
|
const app = this;
|
|
744
787
|
return {
|
|
@@ -1048,6 +1091,10 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1048
1091
|
createProject(newProject) {
|
|
1049
1092
|
return app._createProject(session, newProject);
|
|
1050
1093
|
},
|
|
1094
|
+
async transferProject(projectIdToTransfer, newTeamId) {
|
|
1095
|
+
await app._interface.transferProject(session, projectIdToTransfer, newTeamId);
|
|
1096
|
+
await app._refreshProject();
|
|
1097
|
+
},
|
|
1051
1098
|
listOwnedProjects() {
|
|
1052
1099
|
return app._listOwnedProjects(session);
|
|
1053
1100
|
},
|
|
@@ -1058,18 +1105,22 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1058
1105
|
}
|
|
1059
1106
|
_createCustomer(userIdOrTeamId, type, session) {
|
|
1060
1107
|
const app = this;
|
|
1061
|
-
const
|
|
1108
|
+
const customerOptions = type === "user" ? { userId: userIdOrTeamId } : { teamId: userIdOrTeamId };
|
|
1062
1109
|
return {
|
|
1063
1110
|
async getItem(itemId) {
|
|
1064
|
-
|
|
1065
|
-
return app._clientItemFromCrud(result);
|
|
1111
|
+
return await app.getItem({ itemId, ...customerOptions });
|
|
1066
1112
|
},
|
|
1067
1113
|
useItem(itemId) {
|
|
1068
|
-
|
|
1069
|
-
|
|
1114
|
+
return app.useItem({ itemId, ...customerOptions });
|
|
1115
|
+
},
|
|
1116
|
+
async listProducts(options) {
|
|
1117
|
+
return await app.listProducts({ ...options, ...customerOptions });
|
|
1118
|
+
},
|
|
1119
|
+
useProducts(options) {
|
|
1120
|
+
return app.useProducts({ ...options, ...customerOptions });
|
|
1070
1121
|
},
|
|
1071
1122
|
async createCheckoutUrl(options) {
|
|
1072
|
-
return await app._interface.createCheckoutUrl(type, userIdOrTeamId, options.
|
|
1123
|
+
return await app._interface.createCheckoutUrl(type, userIdOrTeamId, options.productId, session, options.returnUrl);
|
|
1073
1124
|
}
|
|
1074
1125
|
};
|
|
1075
1126
|
}
|
|
@@ -1091,6 +1142,26 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1091
1142
|
const crud = (0, import_common3.useAsyncCache)(cache, [session, ownerId, options.itemId], "app.useItem()");
|
|
1092
1143
|
return this._clientItemFromCrud(crud);
|
|
1093
1144
|
}
|
|
1145
|
+
async listProducts(options) {
|
|
1146
|
+
const session = await this._getSession();
|
|
1147
|
+
if ("userId" in options) {
|
|
1148
|
+
const response2 = import_results.Result.orThrow(await this._userProductsCache.getOrWait([session, options.userId, options.cursor ?? null, options.limit ?? null], "write-only"));
|
|
1149
|
+
return this._customerProductsFromResponse(response2);
|
|
1150
|
+
} else if ("teamId" in options) {
|
|
1151
|
+
const response2 = import_results.Result.orThrow(await this._teamProductsCache.getOrWait([session, options.teamId, options.cursor ?? null, options.limit ?? null], "write-only"));
|
|
1152
|
+
return this._customerProductsFromResponse(response2);
|
|
1153
|
+
}
|
|
1154
|
+
const response = import_results.Result.orThrow(await this._customProductsCache.getOrWait([session, options.customCustomerId, options.cursor ?? null, options.limit ?? null], "write-only"));
|
|
1155
|
+
return this._customerProductsFromResponse(response);
|
|
1156
|
+
}
|
|
1157
|
+
useProducts(options) {
|
|
1158
|
+
const session = this._useSession();
|
|
1159
|
+
const cache = "userId" in options ? this._userProductsCache : "teamId" in options ? this._teamProductsCache : this._customProductsCache;
|
|
1160
|
+
const debugLabel = "clientApp.useProducts()";
|
|
1161
|
+
const customerId = "userId" in options ? options.userId : "teamId" in options ? options.teamId : options.customCustomerId;
|
|
1162
|
+
const response = (0, import_common3.useAsyncCache)(cache, [session, customerId, options.cursor ?? null, options.limit ?? null], debugLabel);
|
|
1163
|
+
return this._customerProductsFromResponse(response);
|
|
1164
|
+
}
|
|
1094
1165
|
_currentUserFromCrud(crud, session) {
|
|
1095
1166
|
const currentUser = {
|
|
1096
1167
|
...this._createBaseUser(crud),
|
|
@@ -1099,6 +1170,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1099
1170
|
...this._isInternalProject() ? this._createInternalUserExtra(session) : {},
|
|
1100
1171
|
...this._createCustomer(crud.id, "user", session)
|
|
1101
1172
|
};
|
|
1173
|
+
(0, import_users.attachUserDestructureGuard)(currentUser);
|
|
1102
1174
|
Object.freeze(currentUser);
|
|
1103
1175
|
return currentUser;
|
|
1104
1176
|
}
|
|
@@ -1332,7 +1404,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1332
1404
|
useUser(options) {
|
|
1333
1405
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1334
1406
|
const session = this._useSession(options?.tokenStore);
|
|
1335
|
-
let crud = (0, import_common3.useAsyncCache)(this._currentUserCache, [session], "useUser()");
|
|
1407
|
+
let crud = (0, import_common3.useAsyncCache)(this._currentUserCache, [session], "clientApp.useUser()");
|
|
1336
1408
|
if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists[deprecated]") {
|
|
1337
1409
|
crud = null;
|
|
1338
1410
|
}
|
|
@@ -1419,7 +1491,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1419
1491
|
return this._getTokenPartialUserFromSession(session, options);
|
|
1420
1492
|
}
|
|
1421
1493
|
case "convex": {
|
|
1422
|
-
const result = (0, import_common3.useAsyncCache)(this._convexPartialUserCache, [options.ctx], "usePartialUser(
|
|
1494
|
+
const result = (0, import_common3.useAsyncCache)(this._convexPartialUserCache, [options.ctx], "clientApp.usePartialUser()");
|
|
1423
1495
|
return result;
|
|
1424
1496
|
}
|
|
1425
1497
|
default: {
|
|
@@ -1429,7 +1501,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1429
1501
|
}
|
|
1430
1502
|
getConvexClientAuth(options) {
|
|
1431
1503
|
return async (args) => {
|
|
1432
|
-
const session = await this._getSession(options.tokenStore);
|
|
1504
|
+
const session = await this._getSession(options.tokenStore ?? this._tokenStoreInit);
|
|
1433
1505
|
if (!args.forceRefreshToken) {
|
|
1434
1506
|
const tokens2 = await session.getOrFetchLikelyValidTokens(2e4);
|
|
1435
1507
|
return tokens2?.accessToken.token ?? null;
|
|
@@ -1441,7 +1513,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1441
1513
|
async getConvexHttpClientAuth(options) {
|
|
1442
1514
|
const session = await this._getSession(options.tokenStore);
|
|
1443
1515
|
const tokens = await session.getOrFetchLikelyValidTokens(2e4);
|
|
1444
|
-
return tokens?.accessToken.token ??
|
|
1516
|
+
return tokens?.accessToken.token ?? "";
|
|
1445
1517
|
}
|
|
1446
1518
|
async _updateClientUser(update, session) {
|
|
1447
1519
|
const res = await this._interface.updateClientUser((0, import_users.userUpdateOptionsToCrud)(update), session);
|
|
@@ -1779,7 +1851,7 @@ ${url}`);
|
|
|
1779
1851
|
return this._clientProjectFromCrud(crud);
|
|
1780
1852
|
}
|
|
1781
1853
|
useProject() {
|
|
1782
|
-
const crud = (0, import_common3.useAsyncCache)(this._currentProjectCache, [], "useProject()");
|
|
1854
|
+
const crud = (0, import_common3.useAsyncCache)(this._currentProjectCache, [], "clientApp.useProject()");
|
|
1783
1855
|
return (0, import_react2.useMemo)(() => this._clientProjectFromCrud(crud), [crud]);
|
|
1784
1856
|
}
|
|
1785
1857
|
async _listOwnedProjects(session) {
|
|
@@ -1792,7 +1864,7 @@ ${url}`);
|
|
|
1792
1864
|
}
|
|
1793
1865
|
_useOwnedProjects(session) {
|
|
1794
1866
|
this._ensureInternalProject();
|
|
1795
|
-
const projects = (0, import_common3.useAsyncCache)(this._ownedProjectsCache, [session], "useOwnedProjects()");
|
|
1867
|
+
const projects = (0, import_common3.useAsyncCache)(this._ownedProjectsCache, [session], "clientApp.useOwnedProjects()");
|
|
1796
1868
|
return (0, import_react2.useMemo)(() => projects.map((j) => this._getOwnedAdminApp(j.id, session)._adminOwnedProjectFromCrud(
|
|
1797
1869
|
j,
|
|
1798
1870
|
() => this._refreshOwnedProjects(session)
|
|
@@ -1837,7 +1909,9 @@ ${url}`);
|
|
|
1837
1909
|
return clientApp;
|
|
1838
1910
|
}
|
|
1839
1911
|
return new __StackClientAppImplIncomplete({
|
|
1840
|
-
...json,
|
|
1912
|
+
...(0, import_objects.omit)(json, ["uniqueIdentifier"])
|
|
1913
|
+
}, {
|
|
1914
|
+
uniqueIdentifier: json.uniqueIdentifier,
|
|
1841
1915
|
checkString: providedCheckString
|
|
1842
1916
|
});
|
|
1843
1917
|
}
|
|
@@ -1869,6 +1943,7 @@ ${url}`);
|
|
|
1869
1943
|
await this._currentUserCache.forceSetCachedValueAsync([await this._getSession()], import_results.Result.fromPromise(userJsonPromise));
|
|
1870
1944
|
});
|
|
1871
1945
|
},
|
|
1946
|
+
getConstructorOptions: () => this._options,
|
|
1872
1947
|
sendRequest: async (path, requestOptions, requestType = "client") => {
|
|
1873
1948
|
return await this._interface.sendClientRequest(path, requestOptions, await this._getSession(), requestType);
|
|
1874
1949
|
}
|