@stackframe/stack-shared 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.
- package/CHANGELOG.md +18 -0
- package/dist/config/schema.d.mts +104 -104
- package/dist/config/schema.d.ts +104 -104
- package/dist/config/schema.js +1 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/esm/config/schema.js +1 -1
- package/dist/esm/config/schema.js.map +1 -1
- package/dist/esm/helpers/production-mode.js +2 -1
- package/dist/esm/helpers/production-mode.js.map +1 -1
- package/dist/esm/interface/admin-interface.js +16 -19
- package/dist/esm/interface/admin-interface.js.map +1 -1
- package/dist/esm/interface/client-interface.js +36 -8
- package/dist/esm/interface/client-interface.js.map +1 -1
- package/dist/esm/interface/crud/items.js +22 -0
- package/dist/esm/interface/crud/items.js.map +1 -0
- package/dist/esm/interface/crud/users.js +1 -1
- package/dist/esm/interface/crud/users.js.map +1 -1
- package/dist/esm/interface/server-interface.js +21 -0
- package/dist/esm/interface/server-interface.js.map +1 -1
- package/dist/esm/known-errors.js +14 -5
- package/dist/esm/known-errors.js.map +1 -1
- package/dist/esm/schema-fields.js +31 -1
- package/dist/esm/schema-fields.js.map +1 -1
- package/dist/esm/utils/jwt.js +42 -37
- package/dist/esm/utils/jwt.js.map +1 -1
- package/dist/esm/utils/types.js.map +1 -1
- package/dist/esm/utils/urls.js +54 -0
- package/dist/esm/utils/urls.js.map +1 -1
- package/dist/helpers/password.d.mts +3 -0
- package/dist/helpers/password.d.ts +3 -0
- package/dist/helpers/production-mode.js +2 -1
- package/dist/helpers/production-mode.js.map +1 -1
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/interface/admin-interface.d.mts +5 -9
- package/dist/interface/admin-interface.d.ts +5 -9
- package/dist/interface/admin-interface.js +16 -19
- package/dist/interface/admin-interface.js.map +1 -1
- package/dist/interface/client-interface.d.mts +14 -8
- package/dist/interface/client-interface.d.ts +14 -8
- package/dist/interface/client-interface.js +36 -8
- package/dist/interface/client-interface.js.map +1 -1
- package/dist/interface/crud/items.d.mts +30 -0
- package/dist/interface/crud/items.d.ts +30 -0
- package/dist/interface/crud/items.js +47 -0
- package/dist/interface/crud/items.js.map +1 -0
- package/dist/interface/crud/project-api-keys.d.mts +4 -4
- package/dist/interface/crud/project-api-keys.d.ts +4 -4
- package/dist/interface/crud/projects.d.mts +7 -7
- package/dist/interface/crud/projects.d.ts +7 -7
- package/dist/interface/crud/users.js +1 -1
- package/dist/interface/crud/users.js.map +1 -1
- package/dist/interface/server-interface.d.mts +6 -0
- package/dist/interface/server-interface.d.ts +6 -0
- package/dist/interface/server-interface.js +21 -0
- package/dist/interface/server-interface.js.map +1 -1
- package/dist/known-errors.d.mts +4 -1
- package/dist/known-errors.d.ts +4 -1
- package/dist/known-errors.js +14 -5
- package/dist/known-errors.js.map +1 -1
- package/dist/schema-fields.d.mts +6 -2
- package/dist/schema-fields.d.ts +6 -2
- package/dist/schema-fields.js +31 -0
- package/dist/schema-fields.js.map +1 -1
- package/dist/utils/jwt.d.mts +11 -11
- package/dist/utils/jwt.d.ts +11 -11
- package/dist/utils/jwt.js +44 -42
- package/dist/utils/jwt.js.map +1 -1
- package/dist/utils/types.d.mts +11 -1
- package/dist/utils/types.d.ts +11 -1
- package/dist/utils/types.js.map +1 -1
- package/dist/utils/urls.d.mts +3 -1
- package/dist/utils/urls.d.ts +3 -1
- package/dist/utils/urls.js +56 -0
- package/dist/utils/urls.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as yup from 'yup';
|
|
2
2
|
import { KnownErrors } from '../known-errors.mjs';
|
|
3
|
+
import { inlineOfferSchema } from '../schema-fields.mjs';
|
|
3
4
|
import { InternalSession, RefreshToken, AccessToken } from '../sessions.mjs';
|
|
4
5
|
import { ReadonlyJson } from '../utils/json.mjs';
|
|
5
6
|
import { PublicKeyCredentialCreationOptionsJSON, RegistrationResponseJSON, PublicKeyCredentialRequestOptionsJSON, AuthenticationResponseJSON } from '@simplewebauthn/types';
|
|
@@ -7,6 +8,7 @@ import { Result } from '../utils/results.mjs';
|
|
|
7
8
|
import { ConnectedAccountAccessTokenCrud } from './crud/connected-accounts.mjs';
|
|
8
9
|
import { ContactChannelsCrud } from './crud/contact-channels.mjs';
|
|
9
10
|
import { CurrentUserCrud } from './crud/current-user.mjs';
|
|
11
|
+
import { ItemCrud } from './crud/items.mjs';
|
|
10
12
|
import { NotificationPreferenceCrud } from './crud/notification-preferences.mjs';
|
|
11
13
|
import { UserApiKeysCrud, TeamApiKeysCrud, userApiKeysCreateInputSchema, userApiKeysCreateOutputSchema, teamApiKeysCreateInputSchema, teamApiKeysCreateOutputSchema } from './crud/project-api-keys.mjs';
|
|
12
14
|
import { ProjectPermissionsCrud } from './crud/project-permissions.mjs';
|
|
@@ -17,6 +19,8 @@ import { TeamMemberProfilesCrud } from './crud/team-member-profiles.mjs';
|
|
|
17
19
|
import { TeamPermissionsCrud } from './crud/team-permissions.mjs';
|
|
18
20
|
import { TeamsCrud } from './crud/teams.mjs';
|
|
19
21
|
import '../utils/errors.mjs';
|
|
22
|
+
import '../utils/currencies.mjs';
|
|
23
|
+
import '../utils/dates.mjs';
|
|
20
24
|
import 'jose';
|
|
21
25
|
import '../crud.mjs';
|
|
22
26
|
import '../utils/types.mjs';
|
|
@@ -131,12 +135,12 @@ declare class StackClientInterface {
|
|
|
131
135
|
accessToken: string;
|
|
132
136
|
refreshToken: string;
|
|
133
137
|
}, never>>;
|
|
134
|
-
signInWithMagicLink(code: string): Promise<Result<{
|
|
138
|
+
signInWithMagicLink(code: string, session: InternalSession): Promise<Result<{
|
|
135
139
|
newUser: boolean;
|
|
136
140
|
accessToken: string;
|
|
137
141
|
refreshToken: string;
|
|
138
142
|
}, KnownErrors["VerificationCodeError"]>>;
|
|
139
|
-
signInWithMfa(totp: string, code: string): Promise<Result<{
|
|
143
|
+
signInWithMfa(totp: string, code: string, session: InternalSession): Promise<Result<{
|
|
140
144
|
newUser: boolean;
|
|
141
145
|
accessToken: string;
|
|
142
146
|
refreshToken: string;
|
|
@@ -144,7 +148,7 @@ declare class StackClientInterface {
|
|
|
144
148
|
signInWithPasskey(body: {
|
|
145
149
|
authentication_response: AuthenticationResponseJSON;
|
|
146
150
|
code: string;
|
|
147
|
-
}): Promise<Result<{
|
|
151
|
+
}, session: InternalSession): Promise<Result<{
|
|
148
152
|
accessToken: string;
|
|
149
153
|
refreshToken: string;
|
|
150
154
|
}, KnownErrors["PasskeyAuthenticationFailed"]>>;
|
|
@@ -157,12 +161,8 @@ declare class StackClientInterface {
|
|
|
157
161
|
state: string;
|
|
158
162
|
type: "authenticate" | "link";
|
|
159
163
|
providerScope?: string;
|
|
160
|
-
} & ({
|
|
161
|
-
type: "authenticate";
|
|
162
|
-
} | {
|
|
163
|
-
type: "link";
|
|
164
164
|
session: InternalSession;
|
|
165
|
-
})
|
|
165
|
+
}): Promise<string>;
|
|
166
166
|
callOAuthCallback(options: {
|
|
167
167
|
oauthParams: URLSearchParams;
|
|
168
168
|
redirectUri: string;
|
|
@@ -287,6 +287,12 @@ declare class StackClientInterface {
|
|
|
287
287
|
deleteOAuthProvider(userId: string, providerId: string, session: InternalSession | null, requestType?: "client" | "server" | "admin"): Promise<{
|
|
288
288
|
success: boolean;
|
|
289
289
|
}>;
|
|
290
|
+
getItem(options: {
|
|
291
|
+
teamId?: string;
|
|
292
|
+
userId?: string;
|
|
293
|
+
itemId: string;
|
|
294
|
+
}, session: InternalSession | null): Promise<ItemCrud['Client']['Read']>;
|
|
295
|
+
createCheckoutUrl(customer_id: string, offerIdOrInline: string | yup.InferType<typeof inlineOfferSchema>, session: InternalSession | null): Promise<string>;
|
|
290
296
|
}
|
|
291
297
|
|
|
292
298
|
export { type ClientInterfaceOptions, StackClientInterface };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as yup from 'yup';
|
|
2
2
|
import { KnownErrors } from '../known-errors.js';
|
|
3
|
+
import { inlineOfferSchema } from '../schema-fields.js';
|
|
3
4
|
import { InternalSession, RefreshToken, AccessToken } from '../sessions.js';
|
|
4
5
|
import { ReadonlyJson } from '../utils/json.js';
|
|
5
6
|
import { PublicKeyCredentialCreationOptionsJSON, RegistrationResponseJSON, PublicKeyCredentialRequestOptionsJSON, AuthenticationResponseJSON } from '@simplewebauthn/types';
|
|
@@ -7,6 +8,7 @@ import { Result } from '../utils/results.js';
|
|
|
7
8
|
import { ConnectedAccountAccessTokenCrud } from './crud/connected-accounts.js';
|
|
8
9
|
import { ContactChannelsCrud } from './crud/contact-channels.js';
|
|
9
10
|
import { CurrentUserCrud } from './crud/current-user.js';
|
|
11
|
+
import { ItemCrud } from './crud/items.js';
|
|
10
12
|
import { NotificationPreferenceCrud } from './crud/notification-preferences.js';
|
|
11
13
|
import { UserApiKeysCrud, TeamApiKeysCrud, userApiKeysCreateInputSchema, userApiKeysCreateOutputSchema, teamApiKeysCreateInputSchema, teamApiKeysCreateOutputSchema } from './crud/project-api-keys.js';
|
|
12
14
|
import { ProjectPermissionsCrud } from './crud/project-permissions.js';
|
|
@@ -17,6 +19,8 @@ import { TeamMemberProfilesCrud } from './crud/team-member-profiles.js';
|
|
|
17
19
|
import { TeamPermissionsCrud } from './crud/team-permissions.js';
|
|
18
20
|
import { TeamsCrud } from './crud/teams.js';
|
|
19
21
|
import '../utils/errors.js';
|
|
22
|
+
import '../utils/currencies.js';
|
|
23
|
+
import '../utils/dates.js';
|
|
20
24
|
import 'jose';
|
|
21
25
|
import '../crud.js';
|
|
22
26
|
import '../utils/types.js';
|
|
@@ -131,12 +135,12 @@ declare class StackClientInterface {
|
|
|
131
135
|
accessToken: string;
|
|
132
136
|
refreshToken: string;
|
|
133
137
|
}, never>>;
|
|
134
|
-
signInWithMagicLink(code: string): Promise<Result<{
|
|
138
|
+
signInWithMagicLink(code: string, session: InternalSession): Promise<Result<{
|
|
135
139
|
newUser: boolean;
|
|
136
140
|
accessToken: string;
|
|
137
141
|
refreshToken: string;
|
|
138
142
|
}, KnownErrors["VerificationCodeError"]>>;
|
|
139
|
-
signInWithMfa(totp: string, code: string): Promise<Result<{
|
|
143
|
+
signInWithMfa(totp: string, code: string, session: InternalSession): Promise<Result<{
|
|
140
144
|
newUser: boolean;
|
|
141
145
|
accessToken: string;
|
|
142
146
|
refreshToken: string;
|
|
@@ -144,7 +148,7 @@ declare class StackClientInterface {
|
|
|
144
148
|
signInWithPasskey(body: {
|
|
145
149
|
authentication_response: AuthenticationResponseJSON;
|
|
146
150
|
code: string;
|
|
147
|
-
}): Promise<Result<{
|
|
151
|
+
}, session: InternalSession): Promise<Result<{
|
|
148
152
|
accessToken: string;
|
|
149
153
|
refreshToken: string;
|
|
150
154
|
}, KnownErrors["PasskeyAuthenticationFailed"]>>;
|
|
@@ -157,12 +161,8 @@ declare class StackClientInterface {
|
|
|
157
161
|
state: string;
|
|
158
162
|
type: "authenticate" | "link";
|
|
159
163
|
providerScope?: string;
|
|
160
|
-
} & ({
|
|
161
|
-
type: "authenticate";
|
|
162
|
-
} | {
|
|
163
|
-
type: "link";
|
|
164
164
|
session: InternalSession;
|
|
165
|
-
})
|
|
165
|
+
}): Promise<string>;
|
|
166
166
|
callOAuthCallback(options: {
|
|
167
167
|
oauthParams: URLSearchParams;
|
|
168
168
|
redirectUri: string;
|
|
@@ -287,6 +287,12 @@ declare class StackClientInterface {
|
|
|
287
287
|
deleteOAuthProvider(userId: string, providerId: string, session: InternalSession | null, requestType?: "client" | "server" | "admin"): Promise<{
|
|
288
288
|
success: boolean;
|
|
289
289
|
}>;
|
|
290
|
+
getItem(options: {
|
|
291
|
+
teamId?: string;
|
|
292
|
+
userId?: string;
|
|
293
|
+
itemId: string;
|
|
294
|
+
}, session: InternalSession | null): Promise<ItemCrud['Client']['Read']>;
|
|
295
|
+
createCheckoutUrl(customer_id: string, offerIdOrInline: string | yup.InferType<typeof inlineOfferSchema>, session: InternalSession | null): Promise<string>;
|
|
290
296
|
}
|
|
291
297
|
|
|
292
298
|
export { type ClientInterfaceOptions, StackClientInterface };
|
|
@@ -236,6 +236,7 @@ var StackClientInterface = class {
|
|
|
236
236
|
...tokenObj?.refreshToken ? {
|
|
237
237
|
"X-Stack-Refresh-Token": tokenObj.refreshToken.token
|
|
238
238
|
} : {},
|
|
239
|
+
"X-Stack-Allow-Anonymous-User": "true",
|
|
239
240
|
..."publishableClientKey" in this.options ? {
|
|
240
241
|
"X-Stack-Publishable-Client-Key": this.options.publishableClientKey
|
|
241
242
|
} : {},
|
|
@@ -679,7 +680,7 @@ var StackClientInterface = class {
|
|
|
679
680
|
refreshToken: result.refresh_token
|
|
680
681
|
});
|
|
681
682
|
}
|
|
682
|
-
async signInWithMagicLink(code) {
|
|
683
|
+
async signInWithMagicLink(code, session) {
|
|
683
684
|
const res = await this.sendClientRequestAndCatchKnownError(
|
|
684
685
|
"/auth/otp/sign-in",
|
|
685
686
|
{
|
|
@@ -691,7 +692,7 @@ var StackClientInterface = class {
|
|
|
691
692
|
code
|
|
692
693
|
})
|
|
693
694
|
},
|
|
694
|
-
|
|
695
|
+
session,
|
|
695
696
|
[import_known_errors.KnownErrors.VerificationCodeError]
|
|
696
697
|
);
|
|
697
698
|
if (res.status === "error") {
|
|
@@ -704,7 +705,7 @@ var StackClientInterface = class {
|
|
|
704
705
|
newUser: result.is_new_user
|
|
705
706
|
});
|
|
706
707
|
}
|
|
707
|
-
async signInWithMfa(totp, code) {
|
|
708
|
+
async signInWithMfa(totp, code, session) {
|
|
708
709
|
const res = await this.sendClientRequestAndCatchKnownError(
|
|
709
710
|
"/auth/mfa/sign-in",
|
|
710
711
|
{
|
|
@@ -718,7 +719,7 @@ var StackClientInterface = class {
|
|
|
718
719
|
code
|
|
719
720
|
})
|
|
720
721
|
},
|
|
721
|
-
|
|
722
|
+
session,
|
|
722
723
|
[import_known_errors.KnownErrors.VerificationCodeError]
|
|
723
724
|
);
|
|
724
725
|
if (res.status === "error") {
|
|
@@ -731,7 +732,7 @@ var StackClientInterface = class {
|
|
|
731
732
|
newUser: result.is_new_user
|
|
732
733
|
});
|
|
733
734
|
}
|
|
734
|
-
async signInWithPasskey(body) {
|
|
735
|
+
async signInWithPasskey(body, session) {
|
|
735
736
|
const res = await this.sendClientRequestAndCatchKnownError(
|
|
736
737
|
"/auth/passkey/sign-in",
|
|
737
738
|
{
|
|
@@ -741,7 +742,7 @@ var StackClientInterface = class {
|
|
|
741
742
|
},
|
|
742
743
|
body: JSON.stringify(body)
|
|
743
744
|
},
|
|
744
|
-
|
|
745
|
+
session,
|
|
745
746
|
[import_known_errors.KnownErrors.PasskeyAuthenticationFailed]
|
|
746
747
|
);
|
|
747
748
|
if (res.status === "error") {
|
|
@@ -776,12 +777,14 @@ var StackClientInterface = class {
|
|
|
776
777
|
url.searchParams.set("response_type", "code");
|
|
777
778
|
url.searchParams.set("type", options.type);
|
|
778
779
|
url.searchParams.set("error_redirect_url", options.errorRedirectUrl);
|
|
780
|
+
const tokens = await options.session.getOrFetchLikelyValidTokens(2e4);
|
|
781
|
+
if (tokens) {
|
|
782
|
+
url.searchParams.set("token", tokens.accessToken.token);
|
|
783
|
+
}
|
|
779
784
|
if (options.afterCallbackRedirectUrl) {
|
|
780
785
|
url.searchParams.set("after_callback_redirect_url", options.afterCallbackRedirectUrl);
|
|
781
786
|
}
|
|
782
787
|
if (options.type === "link") {
|
|
783
|
-
const tokens = await options.session.getOrFetchLikelyValidTokens(2e4);
|
|
784
|
-
url.searchParams.set("token", tokens?.accessToken.token || "");
|
|
785
788
|
if (options.providerScope) {
|
|
786
789
|
url.searchParams.set("provider_scope", options.providerScope);
|
|
787
790
|
}
|
|
@@ -1329,6 +1332,31 @@ var StackClientInterface = class {
|
|
|
1329
1332
|
);
|
|
1330
1333
|
return response.json();
|
|
1331
1334
|
}
|
|
1335
|
+
async getItem(options, session) {
|
|
1336
|
+
const customerId = options.teamId ?? options.userId;
|
|
1337
|
+
const response = await this.sendClientRequest(
|
|
1338
|
+
`/payments/items/${customerId}/${options.itemId}`,
|
|
1339
|
+
{},
|
|
1340
|
+
session
|
|
1341
|
+
);
|
|
1342
|
+
return await response.json();
|
|
1343
|
+
}
|
|
1344
|
+
async createCheckoutUrl(customer_id, offerIdOrInline, session) {
|
|
1345
|
+
const offerBody = typeof offerIdOrInline === "string" ? { offer_id: offerIdOrInline } : { inline_offer: offerIdOrInline };
|
|
1346
|
+
const response = await this.sendClientRequest(
|
|
1347
|
+
"/payments/purchases/create-purchase-url",
|
|
1348
|
+
{
|
|
1349
|
+
method: "POST",
|
|
1350
|
+
headers: {
|
|
1351
|
+
"content-type": "application/json"
|
|
1352
|
+
},
|
|
1353
|
+
body: JSON.stringify({ customer_id, ...offerBody })
|
|
1354
|
+
},
|
|
1355
|
+
session
|
|
1356
|
+
);
|
|
1357
|
+
const { url } = await response.json();
|
|
1358
|
+
return url;
|
|
1359
|
+
}
|
|
1332
1360
|
};
|
|
1333
1361
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1334
1362
|
0 && (module.exports = {
|