@stackframe/js 2.8.31 → 2.8.34

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.
Files changed (35) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/esm/lib/auth.js +3 -2
  3. package/dist/esm/lib/auth.js.map +1 -1
  4. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +13 -8
  5. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
  6. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +45 -8
  7. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  8. package/dist/esm/lib/stack-app/apps/implementations/common.js +1 -1
  9. package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
  10. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +58 -6
  11. package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  12. package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
  13. package/dist/esm/lib/stack-app/common.js.map +1 -1
  14. package/dist/esm/lib/stack-app/projects/index.js.map +1 -1
  15. package/dist/esm/lib/stack-app/teams/index.js.map +1 -1
  16. package/dist/esm/lib/stack-app/users/index.js.map +1 -1
  17. package/dist/index.d.mts +43 -7
  18. package/dist/index.d.ts +43 -7
  19. package/dist/lib/auth.js +3 -2
  20. package/dist/lib/auth.js.map +1 -1
  21. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +13 -8
  22. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
  23. package/dist/lib/stack-app/apps/implementations/client-app-impl.js +45 -8
  24. package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  25. package/dist/lib/stack-app/apps/implementations/common.js +1 -1
  26. package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
  27. package/dist/lib/stack-app/apps/implementations/server-app-impl.js +58 -6
  28. package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
  29. package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
  30. package/dist/lib/stack-app/common.js.map +1 -1
  31. package/dist/lib/stack-app/customers/index.js.map +1 -1
  32. package/dist/lib/stack-app/projects/index.js.map +1 -1
  33. package/dist/lib/stack-app/teams/index.js.map +1 -1
  34. package/dist/lib/stack-app/users/index.js.map +1 -1
  35. package/package.json +2 -2
@@ -153,6 +153,16 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
153
153
  return results;
154
154
  }
155
155
  );
156
+ this._userItemCache = (0, import_common2.createCacheBySession)(
157
+ async (session, [userId, itemId]) => {
158
+ return await this._interface.getItem({ userId, itemId }, session);
159
+ }
160
+ );
161
+ this._teamItemCache = (0, import_common2.createCacheBySession)(
162
+ async (session, [teamId, itemId]) => {
163
+ return await this._interface.getItem({ teamId, itemId }, session);
164
+ }
165
+ );
156
166
  this._anonymousSignUpInProgress = null;
157
167
  this._memoryTokenStore = (0, import_common2.createEmptyTokenStore)();
158
168
  this._nextServerCookiesTokenStores = /* @__PURE__ */ new WeakMap();
@@ -545,6 +555,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
545
555
  profileImageUrl: crud.profile_image_url,
546
556
  clientMetadata: crud.client_metadata,
547
557
  clientReadOnlyMetadata: crud.client_read_only_metadata,
558
+ ...this._createCustomer(crud.id, "team", session),
548
559
  async inviteUser(options) {
549
560
  await app._interface.sendTeamInvitation({
550
561
  teamId: crud.id,
@@ -624,6 +635,14 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
624
635
  }
625
636
  };
626
637
  }
638
+ _clientItemFromCrud(crud) {
639
+ const app = this;
640
+ return {
641
+ displayName: crud.display_name,
642
+ quantity: crud.quantity,
643
+ nonNegativeQuantity: Math.max(0, crud.quantity)
644
+ };
645
+ }
627
646
  _createAuth(session) {
628
647
  const app = this;
629
648
  return {
@@ -866,12 +885,26 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
866
885
  }
867
886
  };
868
887
  }
888
+ _createCustomer(userIdOrTeamId, type, session) {
889
+ const app = this;
890
+ const cache = type === "user" ? app._userItemCache : app._teamItemCache;
891
+ return {
892
+ async getItem(itemId) {
893
+ const result = import_results.Result.orThrow(await cache.getOrWait([session, userIdOrTeamId, itemId], "write-only"));
894
+ return app._clientItemFromCrud(result);
895
+ },
896
+ async createCheckoutUrl(offerIdOrInline) {
897
+ return await app._interface.createCheckoutUrl(userIdOrTeamId, offerIdOrInline, session);
898
+ }
899
+ };
900
+ }
869
901
  _currentUserFromCrud(crud, session) {
870
902
  const currentUser = {
871
903
  ...this._createBaseUser(crud),
872
904
  ...this._createAuth(session),
873
905
  ...this._createUserExtraFromCurrent(crud, session),
874
- ...this._isInternalProject() ? this._createInternalUserExtra(session) : {}
906
+ ...this._isInternalProject() ? this._createInternalUserExtra(session) : {},
907
+ ...this._createCustomer(crud.id, "user", session)
875
908
  };
876
909
  Object.freeze(currentUser);
877
910
  return currentUser;
@@ -1063,7 +1096,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1063
1096
  this._ensurePersistentTokenStore(options?.tokenStore);
1064
1097
  const session = await this._getSession(options?.tokenStore);
1065
1098
  let crud = import_results.Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only"));
1066
- if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists") {
1099
+ if (crud?.is_anonymous && options?.or !== "anonymous" && options?.or !== "anonymous-if-exists[deprecated]") {
1067
1100
  crud = null;
1068
1101
  }
1069
1102
  if (crud === null) {
@@ -1077,10 +1110,10 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1077
1110
  }
1078
1111
  case "anonymous": {
1079
1112
  const tokens = await this._signUpAnonymously();
1080
- return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists" }) ?? (0, import_errors.throwErr)("Something went wrong while signing up anonymously");
1113
+ return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists[deprecated]" }) ?? (0, import_errors.throwErr)("Something went wrong while signing up anonymously");
1081
1114
  }
1082
1115
  case void 0:
1083
- case "anonymous-if-exists":
1116
+ case "anonymous-if-exists[deprecated]":
1084
1117
  case "return-null": {
1085
1118
  return null;
1086
1119
  }
@@ -1098,6 +1131,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1098
1131
  throw new Error("signInWithOAuth can currently only be called in a browser environment");
1099
1132
  }
1100
1133
  this._ensurePersistentTokenStore();
1134
+ const session = await this._getSession();
1101
1135
  await (0, import_auth.signInWithOAuth)(
1102
1136
  this._interface,
1103
1137
  {
@@ -1105,7 +1139,8 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1105
1139
  redirectUrl: this.urls.oauthCallback,
1106
1140
  errorRedirectUrl: this.urls.error,
1107
1141
  providerScope: this._oauthScopesOnSignIn[provider]?.join(" ")
1108
- }
1142
+ },
1143
+ session
1109
1144
  );
1110
1145
  }
1111
1146
  /**
@@ -1196,10 +1231,11 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
1196
1231
  }
1197
1232
  async signInWithMagicLink(code, options) {
1198
1233
  this._ensurePersistentTokenStore();
1234
+ const session = await this._getSession();
1199
1235
  let result;
1200
1236
  try {
1201
1237
  result = await this._catchMfaRequiredError(async () => {
1202
- return await this._interface.signInWithMagicLink(code);
1238
+ return await this._interface.signInWithMagicLink(code, session);
1203
1239
  });
1204
1240
  } catch (e) {
1205
1241
  if (import_stack_shared.KnownErrors.InvalidTotpCode.isInstance(e)) {
@@ -1309,10 +1345,11 @@ ${url}`);
1309
1345
  */
1310
1346
  async signInWithMfa(totp, code, options) {
1311
1347
  this._ensurePersistentTokenStore();
1348
+ const session = await this._getSession();
1312
1349
  let result;
1313
1350
  try {
1314
1351
  result = await this._catchMfaRequiredError(async () => {
1315
- return await this._interface.signInWithMfa(totp, code);
1352
+ return await this._interface.signInWithMfa(totp, code, session);
1316
1353
  });
1317
1354
  } catch (e) {
1318
1355
  if (e instanceof import_stack_shared.KnownErrors.InvalidTotpCode) {
@@ -1349,7 +1386,7 @@ ${url}`);
1349
1386
  }
1350
1387
  options_json.rpId = window.location.hostname;
1351
1388
  const authentication_response = await (0, import_browser.startAuthentication)({ optionsJSON: options_json });
1352
- return await this._interface.signInWithPasskey({ authentication_response, code });
1389
+ return await this._interface.signInWithPasskey({ authentication_response, code }, session);
1353
1390
  });
1354
1391
  } catch (error) {
1355
1392
  if (error instanceof import_browser.WebAuthnError) {