@stackframe/stack 2.4.3 → 2.4.6

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.
@@ -16,6 +16,7 @@ import { filterUndefined, omit } from "@stackframe/stack-shared/dist/utils/objec
16
16
  import { neverResolve, resolved, runAsynchronously, wait } from "@stackframe/stack-shared/dist/utils/promises";
17
17
  import { AsyncCache } from "@stackframe/stack-shared/dist/utils/caches";
18
18
  import { suspend } from "@stackframe/stack-shared/dist/utils/react";
19
+ var clientVersion = "js @stackframe/stack@2.4.6";
19
20
  function permissionDefinitionScopeToType(scope) {
20
21
  return { "any-team": "team", "specific-team": "team", "global": "global" }[scope.type];
21
22
  }
@@ -195,6 +196,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
195
196
  this._interface = new StackClientInterface({
196
197
  baseUrl: options.baseUrl ?? getDefaultBaseUrl(),
197
198
  projectId: options.projectId ?? getDefaultProjectId(),
199
+ clientVersion,
198
200
  publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey()
199
201
  });
200
202
  }
@@ -308,8 +310,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
308
310
  return permissions.find((p) => p.id === permissionId) ?? null;
309
311
  },
310
312
  async hasPermission(scope, permissionId) {
311
- const permissions = await this.listPermissions(scope);
312
- return permissions.some((p) => p.id === permissionId);
313
+ return await this.getPermission(scope, permissionId) !== null;
313
314
  },
314
315
  toJson() {
315
316
  return json;
@@ -368,22 +369,6 @@ var _StackClientAppImpl = class __StackClientAppImpl {
368
369
  return currentUser;
369
370
  }
370
371
  }
371
- _userToJson(user) {
372
- return {
373
- projectId: user.projectId,
374
- id: user.id,
375
- displayName: user.displayName,
376
- primaryEmail: user.primaryEmail,
377
- primaryEmailVerified: user.primaryEmailVerified,
378
- profileImageUrl: user.profileImageUrl,
379
- signedUpAtMillis: user.signedUpAt.getTime(),
380
- clientMetadata: user.clientMetadata,
381
- authMethod: user.authMethod,
382
- hasPassword: user.hasPassword,
383
- authWithEmail: user.authWithEmail,
384
- oauthProviders: user.oauthProviders
385
- };
386
- }
387
372
  _projectAdminFromJson(data, adminInterface, onRefresh) {
388
373
  if (data.id !== adminInterface.projectId) {
389
374
  throw new Error(`The project ID of the provided project JSON (${data.id}) does not match the project ID of the app (${adminInterface.projectId})! This is a Stack bug.`);
@@ -421,6 +406,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
421
406
  return new StackAdminInterface({
422
407
  baseUrl: this._interface.options.baseUrl,
423
408
  projectId: forProjectId,
409
+ clientVersion,
424
410
  projectOwnerTokens: tokenStore
425
411
  });
426
412
  }
@@ -430,12 +416,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
430
416
  get urls() {
431
417
  return getUrls(this._urlOptions);
432
418
  }
433
- _redirectTo(handlerName) {
419
+ async _redirectTo(handlerName) {
434
420
  if (!this.urls[handlerName]) {
435
421
  throw new Error(`No URL for handler name ${handlerName}`);
436
422
  }
437
423
  window.location.href = this.urls[handlerName];
438
- return wait(2e3);
424
+ return await wait(2e3);
439
425
  }
440
426
  async redirectToSignIn() {
441
427
  return await this._redirectTo("signIn");
@@ -755,24 +741,21 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
755
741
  return await this._interface.listTeamMemberPermissions({ teamId, userId, type, direct });
756
742
  });
757
743
  constructor(options) {
758
- if ("interface" in options) {
759
- super({
760
- interface: options.interface,
761
- tokenStore: options.tokenStore,
762
- urls: options.urls
763
- });
764
- } else {
765
- super({
766
- interface: new StackServerInterface({
767
- baseUrl: options.baseUrl ?? getDefaultBaseUrl(),
768
- projectId: options.projectId ?? getDefaultProjectId(),
769
- publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
770
- secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey()
771
- }),
772
- tokenStore: options.tokenStore,
773
- urls: options.urls ?? {}
774
- });
775
- }
744
+ super("interface" in options ? {
745
+ interface: options.interface,
746
+ tokenStore: options.tokenStore,
747
+ urls: options.urls
748
+ } : {
749
+ interface: new StackServerInterface({
750
+ baseUrl: options.baseUrl ?? getDefaultBaseUrl(),
751
+ projectId: options.projectId ?? getDefaultProjectId(),
752
+ clientVersion,
753
+ publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
754
+ secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey()
755
+ }),
756
+ tokenStore: options.tokenStore,
757
+ urls: options.urls ?? {}
758
+ });
776
759
  }
777
760
  _serverUserFromJson(json) {
778
761
  if (json === null)
@@ -856,7 +839,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
856
839
  return permissions.some((p) => p.id === permissionId);
857
840
  },
858
841
  toJson() {
859
- return app._serverUserToJson(this);
842
+ return json;
860
843
  }
861
844
  };
862
845
  }
@@ -928,23 +911,6 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
928
911
  }
929
912
  };
930
913
  }
931
- _serverUserToJson(user) {
932
- return {
933
- projectId: user.projectId,
934
- id: user.id,
935
- displayName: user.displayName,
936
- primaryEmail: user.primaryEmail,
937
- primaryEmailVerified: user.primaryEmailVerified,
938
- profileImageUrl: user.profileImageUrl,
939
- signedUpAtMillis: user.signedUpAt.getTime(),
940
- clientMetadata: user.clientMetadata,
941
- serverMetadata: user.serverMetadata,
942
- authMethod: user.authMethod,
943
- hasPassword: user.hasPassword,
944
- authWithEmail: user.authWithEmail,
945
- oauthProviders: user.oauthProviders
946
- };
947
- }
948
914
  _serverTeamFromJson(json) {
949
915
  const app = this;
950
916
  return {
@@ -1105,6 +1071,7 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
1105
1071
  interface: new StackAdminInterface({
1106
1072
  baseUrl: options.baseUrl ?? getDefaultBaseUrl(),
1107
1073
  projectId: options.projectId ?? getDefaultProjectId(),
1074
+ clientVersion,
1108
1075
  ..."projectOwnerTokens" in options ? {
1109
1076
  projectOwnerTokens: options.projectOwnerTokens
1110
1077
  } : {