@stackframe/stack 2.4.10 → 2.4.12
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 +309 -0
- package/dist/components-core/index.d.mts +1 -1
- package/dist/components-core/index.d.ts +1 -1
- package/dist/esm/lib/stack-app.js +57 -21
- package/dist/esm/lib/stack-app.js.map +1 -1
- package/dist/lib/stack-app.d.mts +5 -3
- package/dist/lib/stack-app.d.ts +5 -3
- package/dist/lib/stack-app.js +57 -21
- package/dist/lib/stack-app.js.map +1 -1
- package/dist/providers/component-provider.d.mts +2 -2
- package/dist/providers/component-provider.d.ts +2 -2
- package/package.json +6 -4
package/dist/lib/stack-app.js
CHANGED
|
@@ -57,7 +57,7 @@ var import_compile_time = require("@stackframe/stack-shared/dist/utils/compile-t
|
|
|
57
57
|
var import_stack_sc = require("@stackframe/stack-sc");
|
|
58
58
|
var cookie = __toESM(require("cookie"));
|
|
59
59
|
var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
|
|
60
|
-
var clientVersion = "js @stackframe/stack@2.4.
|
|
60
|
+
var clientVersion = "js @stackframe/stack@2.4.12";
|
|
61
61
|
function permissionDefinitionScopeToType(scope) {
|
|
62
62
|
return { "any-team": "team", "specific-team": "team", "global": "global" }[scope.type];
|
|
63
63
|
}
|
|
@@ -166,7 +166,7 @@ var createCacheByTokenStore = (fetcher) => {
|
|
|
166
166
|
{
|
|
167
167
|
onSubscribe: ([tokenStore], refresh) => {
|
|
168
168
|
const handlerObj = tokenStore.onChange((newValue, oldValue) => {
|
|
169
|
-
if (
|
|
169
|
+
if (newValue.refreshToken === oldValue?.refreshToken)
|
|
170
170
|
return;
|
|
171
171
|
refresh();
|
|
172
172
|
});
|
|
@@ -175,8 +175,32 @@ var createCacheByTokenStore = (fetcher) => {
|
|
|
175
175
|
}
|
|
176
176
|
);
|
|
177
177
|
};
|
|
178
|
+
var numberOfAppsCreated = 0;
|
|
178
179
|
var _StackClientAppImpl = class __StackClientAppImpl {
|
|
179
|
-
|
|
180
|
+
constructor(_options) {
|
|
181
|
+
this._options = _options;
|
|
182
|
+
if ("interface" in _options) {
|
|
183
|
+
this._interface = _options.interface;
|
|
184
|
+
} else {
|
|
185
|
+
this._interface = new import_stack_shared.StackClientInterface({
|
|
186
|
+
baseUrl: _options.baseUrl ?? getDefaultBaseUrl(),
|
|
187
|
+
projectId: _options.projectId ?? getDefaultProjectId(),
|
|
188
|
+
clientVersion,
|
|
189
|
+
publishableClientKey: _options.publishableClientKey ?? getDefaultPublishableClientKey()
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
this._tokenStoreInit = _options.tokenStore;
|
|
193
|
+
this._urlOptions = _options.urls ?? {};
|
|
194
|
+
if (_options.uniqueIdentifier) {
|
|
195
|
+
this._uniqueIdentifier = _options.uniqueIdentifier;
|
|
196
|
+
this._initUniqueIdentifier();
|
|
197
|
+
}
|
|
198
|
+
numberOfAppsCreated++;
|
|
199
|
+
if (numberOfAppsCreated > 10) {
|
|
200
|
+
console.warn(`You have created more than 10 Stack apps (${numberOfAppsCreated}). This is usually a sign of a memory leak. Make sure to minimize the number of Stack apps per page (usually, one per project).`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
_uniqueIdentifier = void 0;
|
|
180
204
|
_interface;
|
|
181
205
|
_tokenStoreInit;
|
|
182
206
|
_urlOptions;
|
|
@@ -200,24 +224,25 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
200
224
|
_currentUserTeamsCache = createCacheByTokenStore(async (tokenStore) => {
|
|
201
225
|
return await this._interface.listClientUserTeams(tokenStore);
|
|
202
226
|
});
|
|
203
|
-
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
} else {
|
|
207
|
-
this._interface = new import_stack_shared.StackClientInterface({
|
|
208
|
-
baseUrl: options.baseUrl ?? getDefaultBaseUrl(),
|
|
209
|
-
projectId: options.projectId ?? getDefaultProjectId(),
|
|
210
|
-
clientVersion,
|
|
211
|
-
publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey()
|
|
212
|
-
});
|
|
227
|
+
_initUniqueIdentifier() {
|
|
228
|
+
if (!this._uniqueIdentifier) {
|
|
229
|
+
throw new import_errors.StackAssertionError("Unique identifier not initialized");
|
|
213
230
|
}
|
|
214
|
-
this._tokenStoreInit = options.tokenStore;
|
|
215
|
-
this._urlOptions = options.urls ?? {};
|
|
216
|
-
this._uniqueIdentifier = options.uniqueIdentifier ?? (0, import_uuids.generateUuid)();
|
|
217
231
|
if (allClientApps.has(this._uniqueIdentifier)) {
|
|
218
232
|
throw new import_errors.StackAssertionError("A Stack client app with the same unique identifier already exists");
|
|
219
233
|
}
|
|
220
|
-
allClientApps.set(this._uniqueIdentifier, [
|
|
234
|
+
allClientApps.set(this._uniqueIdentifier, [this._options.checkString ?? "default check string", this]);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Cloudflare workers does not allow use of randomness on the global scope (on which the Stack app is probably
|
|
238
|
+
* initialized). For that reason, we generate the unique identifier lazily when it is first needed.
|
|
239
|
+
*/
|
|
240
|
+
_getUniqueIdentifier() {
|
|
241
|
+
if (!this._uniqueIdentifier) {
|
|
242
|
+
this._uniqueIdentifier = (0, import_uuids.generateUuid)();
|
|
243
|
+
this._initUniqueIdentifier();
|
|
244
|
+
}
|
|
245
|
+
return this._uniqueIdentifier;
|
|
221
246
|
}
|
|
222
247
|
_memoryTokenStore = createEmptyTokenStore();
|
|
223
248
|
_requestTokenStores = /* @__PURE__ */ new Map();
|
|
@@ -400,6 +425,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
400
425
|
const currentUser = {
|
|
401
426
|
...this._userFromJson(json),
|
|
402
427
|
tokenStore,
|
|
428
|
+
async refreshAccessToken() {
|
|
429
|
+
await app._interface.refreshAccessToken(tokenStore);
|
|
430
|
+
},
|
|
403
431
|
async updateSelectedTeam(team) {
|
|
404
432
|
await app._updateUser({ selectedTeamId: team?.id ?? null }, tokenStore);
|
|
405
433
|
},
|
|
@@ -477,7 +505,8 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
477
505
|
baseUrl: this._interface.options.baseUrl,
|
|
478
506
|
projectId: forProjectId,
|
|
479
507
|
clientVersion,
|
|
480
|
-
projectOwnerTokens: tokenStore
|
|
508
|
+
projectOwnerTokens: tokenStore,
|
|
509
|
+
refreshProjectOwnerTokens: async () => await this._interface.refreshAccessToken(tokenStore)
|
|
481
510
|
});
|
|
482
511
|
}
|
|
483
512
|
get projectId() {
|
|
@@ -589,7 +618,10 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
589
618
|
if (userJson === null) {
|
|
590
619
|
switch (options?.or) {
|
|
591
620
|
case "redirect": {
|
|
592
|
-
|
|
621
|
+
(0, import_promises.runAsynchronously)(async () => {
|
|
622
|
+
await (0, import_promises.wait)(0);
|
|
623
|
+
router.replace(this.urls.signIn);
|
|
624
|
+
});
|
|
593
625
|
(0, import_react3.suspend)();
|
|
594
626
|
throw new import_errors.StackAssertionError("suspend should never return");
|
|
595
627
|
}
|
|
@@ -786,7 +818,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
786
818
|
publishableClientKey: this._interface.options.publishableClientKey,
|
|
787
819
|
tokenStore: this._tokenStoreInit,
|
|
788
820
|
urls: this._urlOptions,
|
|
789
|
-
uniqueIdentifier: this.
|
|
821
|
+
uniqueIdentifier: this._getUniqueIdentifier()
|
|
790
822
|
};
|
|
791
823
|
},
|
|
792
824
|
setCurrentUser: (userJsonPromise) => {
|
|
@@ -931,6 +963,9 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
931
963
|
const currentUser = {
|
|
932
964
|
...nonCurrentServerUser,
|
|
933
965
|
tokenStore,
|
|
966
|
+
async refreshAccessToken() {
|
|
967
|
+
await app._interface.refreshAccessToken(tokenStore);
|
|
968
|
+
},
|
|
934
969
|
async delete() {
|
|
935
970
|
const res = await nonCurrentServerUser.delete();
|
|
936
971
|
await app._refreshUser(tokenStore);
|
|
@@ -1156,7 +1191,8 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
|
1156
1191
|
projectId: options.projectId ?? getDefaultProjectId(),
|
|
1157
1192
|
clientVersion,
|
|
1158
1193
|
..."projectOwnerTokens" in options ? {
|
|
1159
|
-
projectOwnerTokens: options.projectOwnerTokens
|
|
1194
|
+
projectOwnerTokens: options.projectOwnerTokens,
|
|
1195
|
+
refreshProjectOwnerTokens: options.refreshProjectOwnerTokens
|
|
1160
1196
|
} : {
|
|
1161
1197
|
publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
|
|
1162
1198
|
secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey(),
|