@stackframe/stack-shared 2.5.11 → 2.5.13

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @stackframe/stack-shared
2
2
 
3
+ ## 2.5.13
4
+
5
+ ### Patch Changes
6
+
7
+ - Add server side get connected account
8
+ - @stackframe/stack-sc@2.5.13
9
+
10
+ ## 2.5.12
11
+
12
+ ### Patch Changes
13
+
14
+ - Bugfixes
15
+ - @stackframe/stack-sc@2.5.12
16
+
3
17
  ## 2.5.11
4
18
 
5
19
  ### Patch Changes
@@ -3,7 +3,7 @@ import { AccessToken, InternalSession, RefreshToken } from '../sessions';
3
3
  import { ReadonlyJson } from '../utils/json';
4
4
  import { Result } from "../utils/results";
5
5
  import { CurrentUserCrud } from './crud/current-user';
6
- import { ProviderAccessTokenCrud } from './crud/oauth';
6
+ import { ConnectedAccountAccessTokenCrud } from './crud/oauth';
7
7
  import { InternalProjectsCrud, ProjectsCrud } from './crud/projects';
8
8
  import { TeamPermissionsCrud } from './crud/team-permissions';
9
9
  import { TeamsCrud } from './crud/teams';
@@ -55,7 +55,7 @@ export declare class StackClientInterface {
55
55
  } & ({
56
56
  password: string;
57
57
  } | {
58
- onlyVerifyCode: boolean;
58
+ onlyVerifyCode: true;
59
59
  })): Promise<KnownErrors["VerificationCodeError"] | undefined>;
60
60
  updatePassword(options: {
61
61
  oldPassword: string;
@@ -113,6 +113,6 @@ export declare class StackClientInterface {
113
113
  updateClientUser(update: CurrentUserCrud["Client"]["Update"], session: InternalSession): Promise<void>;
114
114
  listProjects(session: InternalSession): Promise<InternalProjectsCrud['Client']['Read'][]>;
115
115
  createProject(project: InternalProjectsCrud['Client']['Create'], session: InternalSession): Promise<InternalProjectsCrud['Client']['Read']>;
116
- createProviderAccessToken(provider: string, scope: string, session: InternalSession): Promise<ProviderAccessTokenCrud['Client']['Read']>;
116
+ createProviderAccessToken(provider: string, scope: string, session: InternalSession): Promise<ConnectedAccountAccessTokenCrud['Client']['Read']>;
117
117
  createTeamForCurrentUser(data: TeamsCrud['Client']['Create'], session: InternalSession): Promise<TeamsCrud['Client']['Read']>;
118
118
  }
@@ -330,12 +330,15 @@ export class StackClientInterface {
330
330
  }
331
331
  }
332
332
  async resetPassword(options) {
333
- const res = await this.sendClientRequestAndCatchKnownError("/auth/password/reset", {
333
+ const res = await this.sendClientRequestAndCatchKnownError("onlyVerifyCode" in options ? "/auth/password/reset/check-code" : "/auth/password/reset", {
334
334
  method: "POST",
335
335
  headers: {
336
336
  "Content-Type": "application/json"
337
337
  },
338
- body: JSON.stringify(options),
338
+ body: JSON.stringify({
339
+ code: options.code,
340
+ ...("password" in options ? { password: options.password } : {}),
341
+ }),
339
342
  }, null, [KnownErrors.VerificationCodeError]);
340
343
  if (res.status === "error") {
341
344
  return res.error;
@@ -598,7 +601,7 @@ export class StackClientInterface {
598
601
  return json;
599
602
  }
600
603
  async createProviderAccessToken(provider, scope, session) {
601
- const response = await this.sendClientRequest(`/auth/oauth/connected-accounts/${provider}/access-token`, {
604
+ const response = await this.sendClientRequest(`/connected-accounts/me/${provider}/access-token`, {
602
605
  method: "POST",
603
606
  headers: {
604
607
  "content-type": "application/json",
@@ -1,15 +1,15 @@
1
1
  import { CrudTypeOf } from "../../crud";
2
- export declare const providerAccessTokenReadSchema: import("yup").ObjectSchema<{
2
+ export declare const connectedAccountAccessTokenReadSchema: import("yup").ObjectSchema<{
3
3
  access_token: string;
4
4
  }, import("yup").AnyObject, {
5
5
  access_token: undefined;
6
6
  }, "">;
7
- export declare const providerAccessTokenCreateSchema: import("yup").ObjectSchema<{
7
+ export declare const connectedAccountAccessTokenCreateSchema: import("yup").ObjectSchema<{
8
8
  scope: string | undefined;
9
9
  }, import("yup").AnyObject, {
10
10
  scope: undefined;
11
11
  }, "">;
12
- export declare const providerAccessTokenCrud: import("../../crud").CrudSchemaFromOptions<{
12
+ export declare const connectedAccountAccessTokenCrud: import("../../crud").CrudSchemaFromOptions<{
13
13
  clientReadSchema: import("yup").ObjectSchema<{
14
14
  access_token: string;
15
15
  }, import("yup").AnyObject, {
@@ -21,4 +21,4 @@ export declare const providerAccessTokenCrud: import("../../crud").CrudSchemaFro
21
21
  scope: undefined;
22
22
  }, "">;
23
23
  }>;
24
- export type ProviderAccessTokenCrud = CrudTypeOf<typeof providerAccessTokenCrud>;
24
+ export type ConnectedAccountAccessTokenCrud = CrudTypeOf<typeof connectedAccountAccessTokenCrud>;
@@ -1,12 +1,12 @@
1
1
  import { createCrud } from "../../crud";
2
2
  import { yupObject, yupString } from "../../schema-fields";
3
- export const providerAccessTokenReadSchema = yupObject({
3
+ export const connectedAccountAccessTokenReadSchema = yupObject({
4
4
  access_token: yupString().required(),
5
5
  }).required();
6
- export const providerAccessTokenCreateSchema = yupObject({
6
+ export const connectedAccountAccessTokenCreateSchema = yupObject({
7
7
  scope: yupString().optional(),
8
8
  }).required();
9
- export const providerAccessTokenCrud = createCrud({
10
- clientReadSchema: providerAccessTokenReadSchema,
11
- clientCreateSchema: providerAccessTokenCreateSchema,
9
+ export const connectedAccountAccessTokenCrud = createCrud({
10
+ clientReadSchema: connectedAccountAccessTokenReadSchema,
11
+ clientCreateSchema: connectedAccountAccessTokenCreateSchema,
12
12
  });
@@ -3,6 +3,7 @@ import { AccessToken, InternalSession, RefreshToken } from "../sessions";
3
3
  import { Result } from "../utils/results";
4
4
  import { ClientInterfaceOptions, StackClientInterface } from "./clientInterface";
5
5
  import { CurrentUserCrud } from "./crud/current-user";
6
+ import { ConnectedAccountAccessTokenCrud } from "./crud/oauth";
6
7
  import { TeamMembershipsCrud } from "./crud/team-memberships";
7
8
  import { TeamPermissionsCrud } from "./crud/team-permissions";
8
9
  import { TeamsCrud } from "./crud/teams";
@@ -29,13 +30,15 @@ export declare class StackServerInterface extends StackClientInterface {
29
30
  }, InstanceType<E>>>;
30
31
  getServerUserByToken(session: InternalSession): Promise<CurrentUserCrud['Server']['Read'] | null>;
31
32
  getServerUserById(userId: string): Promise<Result<UsersCrud['Server']['Read']>>;
32
- listServerCurrentUserTeamPermissions(options: {
33
- teamId: string;
33
+ listServerTeamPermissions(options: {
34
+ userId?: string;
35
+ teamId?: string;
34
36
  recursive: boolean;
35
37
  }, session: InternalSession): Promise<TeamPermissionsCrud['Server']['Read'][]>;
36
- listServerCurrentUserTeams(session: InternalSession): Promise<TeamsCrud['Server']['Read'][]>;
37
38
  listServerUsers(): Promise<UsersCrud['Server']['Read'][]>;
38
- listServerTeams(): Promise<TeamsCrud['Server']['Read'][]>;
39
+ listServerTeams(options?: {
40
+ userId?: string;
41
+ }): Promise<TeamsCrud['Server']['Read'][]>;
39
42
  listServerTeamUsers(teamId: string): Promise<UsersCrud['Server']['Read'][]>;
40
43
  createServerTeam(data: TeamsCrud['Server']['Create'], session?: InternalSession): Promise<TeamsCrud['Server']['Read']>;
41
44
  updateServerTeam(teamId: string, data: TeamsCrud['Server']['Update']): Promise<TeamsCrud['Server']['Read']>;
@@ -49,6 +52,7 @@ export declare class StackServerInterface extends StackClientInterface {
49
52
  teamId: string;
50
53
  }): Promise<void>;
51
54
  updateServerUser(userId: string, update: UsersCrud['Server']['Update']): Promise<UsersCrud['Server']['Read']>;
55
+ createServerProviderAccessToken(userId: string, provider: string, scope: string): Promise<ConnectedAccountAccessTokenCrud['Server']['Read']>;
52
56
  createServerUserSession(userId: string, expiresInMillis: number): Promise<{
53
57
  accessToken: string;
54
58
  refreshToken: string;
@@ -1,5 +1,6 @@
1
1
  import { KnownErrors } from "../known-errors";
2
2
  import { StackAssertionError } from "../utils/errors";
3
+ import { filterUndefined } from "../utils/objects";
3
4
  import { Result } from "../utils/results";
4
5
  import { StackClientInterface } from "./clientInterface";
5
6
  export class StackServerInterface extends StackClientInterface {
@@ -52,13 +53,12 @@ export class StackServerInterface extends StackClientInterface {
52
53
  return Result.error(new Error("Failed to get user"));
53
54
  return Result.ok(user);
54
55
  }
55
- async listServerCurrentUserTeamPermissions(options, session) {
56
- const response = await this.sendServerRequest(`/team-permissions?team_id=${options.teamId}&user_id=me&recursive=${options.recursive}`, {}, session);
57
- const result = await response.json();
58
- return result.items;
59
- }
60
- async listServerCurrentUserTeams(session) {
61
- const response = await this.sendServerRequest("/teams?user_id=me", {}, session);
56
+ async listServerTeamPermissions(options, session) {
57
+ const response = await this.sendServerRequest("/team-permissions?" + new URLSearchParams(filterUndefined({
58
+ user_id: options.userId,
59
+ team_id: options.teamId,
60
+ recursive: options.recursive.toString(),
61
+ })), {}, session);
62
62
  const result = await response.json();
63
63
  return result.items;
64
64
  }
@@ -67,8 +67,10 @@ export class StackServerInterface extends StackClientInterface {
67
67
  const result = await response.json();
68
68
  return result.items;
69
69
  }
70
- async listServerTeams() {
71
- const response = await this.sendServerRequest("/teams", {}, null);
70
+ async listServerTeams(options) {
71
+ const response = await this.sendServerRequest("/teams?" + new URLSearchParams(filterUndefined({
72
+ user_id: options?.userId,
73
+ })), {}, null);
72
74
  const result = await response.json();
73
75
  return result.items;
74
76
  }
@@ -130,6 +132,16 @@ export class StackServerInterface extends StackClientInterface {
130
132
  }, null);
131
133
  return await response.json();
132
134
  }
135
+ async createServerProviderAccessToken(userId, provider, scope) {
136
+ const response = await this.sendServerRequest(`/connected-accounts/${userId}/${provider}/access-token`, {
137
+ method: "POST",
138
+ headers: {
139
+ "content-type": "application/json",
140
+ },
141
+ body: JSON.stringify({ scope }),
142
+ }, null);
143
+ return await response.json();
144
+ }
133
145
  async createServerUserSession(userId, expiresInMillis) {
134
146
  const response = await this.sendServerRequest("/auth/sessions", {
135
147
  method: "POST",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackframe/stack-shared",
3
- "version": "2.5.11",
3
+ "version": "2.5.13",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -36,7 +36,7 @@
36
36
  "jose": "^5.2.2",
37
37
  "oauth4webapi": "^2.10.3",
38
38
  "uuid": "^9.0.1",
39
- "@stackframe/stack-sc": "2.5.11"
39
+ "@stackframe/stack-sc": "2.5.13"
40
40
  },
41
41
  "devDependencies": {
42
42
  "rimraf": "^5.0.5",