@stackframe/stack-shared 2.8.56 → 2.8.59
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/dist/apps/apps-config.d.mts +6 -0
- package/dist/apps/apps-config.d.ts +6 -0
- package/dist/apps/apps-config.js +6 -0
- package/dist/apps/apps-config.js.map +1 -1
- package/dist/config/migrate-catalogs-to-product-lines.d.mts +12 -0
- package/dist/config/migrate-catalogs-to-product-lines.d.ts +12 -0
- package/dist/config/migrate-catalogs-to-product-lines.js +211 -0
- package/dist/config/migrate-catalogs-to-product-lines.js.map +1 -0
- package/dist/config/schema-fuzzer.test.js +20 -6
- package/dist/config/schema-fuzzer.test.js.map +1 -1
- package/dist/config/schema.d.mts +296 -224
- package/dist/config/schema.d.ts +296 -224
- package/dist/config/schema.js +46 -8
- package/dist/config/schema.js.map +1 -1
- package/dist/esm/apps/apps-config.js +6 -0
- package/dist/esm/apps/apps-config.js.map +1 -1
- package/dist/esm/config/migrate-catalogs-to-product-lines.js +186 -0
- package/dist/esm/config/migrate-catalogs-to-product-lines.js.map +1 -0
- package/dist/esm/config/schema-fuzzer.test.js +20 -6
- package/dist/esm/config/schema-fuzzer.test.js.map +1 -1
- package/dist/esm/config/schema.js +47 -9
- package/dist/esm/config/schema.js.map +1 -1
- package/dist/esm/interface/admin-interface.js +49 -1
- package/dist/esm/interface/admin-interface.js.map +1 -1
- package/dist/esm/interface/client-interface.js +124 -25
- package/dist/esm/interface/client-interface.js.map +1 -1
- package/dist/esm/interface/crud/current-user.js +5 -2
- package/dist/esm/interface/crud/current-user.js.map +1 -1
- package/dist/esm/interface/crud/email-outbox.js +204 -0
- package/dist/esm/interface/crud/email-outbox.js.map +1 -0
- package/dist/esm/interface/crud/emails.js +0 -2
- package/dist/esm/interface/crud/emails.js.map +1 -1
- package/dist/esm/interface/crud/products.js +12 -1
- package/dist/esm/interface/crud/products.js.map +1 -1
- package/dist/esm/interface/crud/projects.js +3 -1
- package/dist/esm/interface/crud/projects.js.map +1 -1
- package/dist/esm/interface/crud/users.js +9 -2
- package/dist/esm/interface/crud/users.js.map +1 -1
- package/dist/esm/interface/server-interface.js +54 -0
- package/dist/esm/interface/server-interface.js.map +1 -1
- package/dist/esm/known-errors.js +69 -1
- package/dist/esm/known-errors.js.map +1 -1
- package/dist/esm/schema-fields.js +27 -3
- package/dist/esm/schema-fields.js.map +1 -1
- package/dist/esm/sessions.js +72 -8
- package/dist/esm/sessions.js.map +1 -1
- package/dist/esm/utils/env.js +13 -2
- package/dist/esm/utils/env.js.map +1 -1
- package/dist/esm/utils/esbuild.js +50 -21
- package/dist/esm/utils/esbuild.js.map +1 -1
- package/dist/esm/utils/globals.js +12 -0
- package/dist/esm/utils/globals.js.map +1 -1
- package/dist/esm/utils/paginated-lists.js +153 -23
- package/dist/esm/utils/paginated-lists.js.map +1 -1
- package/dist/esm/utils/paginated-lists.test.js +842 -0
- package/dist/esm/utils/paginated-lists.test.js.map +1 -0
- package/dist/esm/utils/proxies.js +28 -1
- package/dist/esm/utils/proxies.js.map +1 -1
- package/dist/esm/utils/react.js +7 -3
- package/dist/esm/utils/react.js.map +1 -1
- package/dist/esm/utils/results.js.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/interface/admin-interface.d.mts +26 -3
- package/dist/interface/admin-interface.d.ts +26 -3
- package/dist/interface/admin-interface.js +49 -1
- package/dist/interface/admin-interface.js.map +1 -1
- package/dist/interface/client-interface.d.mts +36 -0
- package/dist/interface/client-interface.d.ts +36 -0
- package/dist/interface/client-interface.js +124 -25
- package/dist/interface/client-interface.js.map +1 -1
- package/dist/interface/crud/current-user.d.mts +23 -6
- package/dist/interface/crud/current-user.d.ts +23 -6
- package/dist/interface/crud/current-user.js +5 -2
- package/dist/interface/crud/current-user.js.map +1 -1
- package/dist/interface/crud/email-outbox.d.mts +1075 -0
- package/dist/interface/crud/email-outbox.d.ts +1075 -0
- package/dist/interface/crud/email-outbox.js +241 -0
- package/dist/interface/crud/email-outbox.js.map +1 -0
- package/dist/interface/crud/emails.d.mts +0 -34
- package/dist/interface/crud/emails.d.ts +0 -34
- package/dist/interface/crud/emails.js +0 -2
- package/dist/interface/crud/emails.js.map +1 -1
- package/dist/interface/crud/products.d.mts +77 -0
- package/dist/interface/crud/products.d.ts +77 -0
- package/dist/interface/crud/products.js +12 -1
- package/dist/interface/crud/products.js.map +1 -1
- package/dist/interface/crud/project-api-keys.d.mts +1 -1
- package/dist/interface/crud/project-api-keys.d.ts +1 -1
- package/dist/interface/crud/projects.d.mts +70 -66
- package/dist/interface/crud/projects.d.ts +70 -66
- package/dist/interface/crud/projects.js +3 -1
- package/dist/interface/crud/projects.js.map +1 -1
- package/dist/interface/crud/team-member-profiles.d.mts +28 -12
- package/dist/interface/crud/team-member-profiles.d.ts +28 -12
- package/dist/interface/crud/users.d.mts +38 -6
- package/dist/interface/crud/users.d.ts +38 -6
- package/dist/interface/crud/users.js +9 -2
- package/dist/interface/crud/users.js.map +1 -1
- package/dist/interface/server-interface.d.mts +52 -0
- package/dist/interface/server-interface.d.ts +52 -0
- package/dist/interface/server-interface.js +54 -0
- package/dist/interface/server-interface.js.map +1 -1
- package/dist/interface/webhooks.d.mts +18 -2
- package/dist/interface/webhooks.d.ts +18 -2
- package/dist/known-errors.d.mts +20 -1
- package/dist/known-errors.d.ts +20 -1
- package/dist/known-errors.js +69 -1
- package/dist/known-errors.js.map +1 -1
- package/dist/schema-fields.d.mts +38 -5
- package/dist/schema-fields.d.ts +38 -5
- package/dist/schema-fields.js +33 -3
- package/dist/schema-fields.js.map +1 -1
- package/dist/sessions.d.mts +35 -4
- package/dist/sessions.d.ts +35 -4
- package/dist/sessions.js +72 -8
- package/dist/sessions.js.map +1 -1
- package/dist/utils/env.d.mts +2 -1
- package/dist/utils/env.d.ts +2 -1
- package/dist/utils/env.js +13 -1
- package/dist/utils/env.js.map +1 -1
- package/dist/utils/esbuild.js +49 -20
- package/dist/utils/esbuild.js.map +1 -1
- package/dist/utils/globals.d.mts +6 -1
- package/dist/utils/globals.d.ts +6 -1
- package/dist/utils/globals.js +13 -0
- package/dist/utils/globals.js.map +1 -1
- package/dist/utils/paginated-lists.d.mts +269 -12
- package/dist/utils/paginated-lists.d.ts +269 -12
- package/dist/utils/paginated-lists.js +153 -23
- package/dist/utils/paginated-lists.js.map +1 -1
- package/dist/utils/paginated-lists.test.d.mts +2 -0
- package/dist/utils/paginated-lists.test.d.ts +2 -0
- package/dist/utils/paginated-lists.test.js +844 -0
- package/dist/utils/paginated-lists.test.js.map +1 -0
- package/dist/utils/proxies.d.mts +8 -1
- package/dist/utils/proxies.d.ts +8 -1
- package/dist/utils/proxies.js +30 -2
- package/dist/utils/proxies.js.map +1 -1
- package/dist/utils/react.d.mts +1 -1
- package/dist/utils/react.d.ts +1 -1
- package/dist/utils/react.js +7 -3
- package/dist/utils/react.js.map +1 -1
- package/dist/utils/results.d.mts +5 -5
- package/dist/utils/results.d.ts +5 -5
- package/dist/utils/results.js.map +1 -1
- package/package.json +5 -4
- package/CHANGELOG.md +0 -1354
- package/dist/esm/interface/crud/config.js +0 -40
- package/dist/esm/interface/crud/config.js.map +0 -1
- package/dist/interface/crud/config.d.mts +0 -49
- package/dist/interface/crud/config.d.ts +0 -49
- package/dist/interface/crud/config.js +0 -79
- package/dist/interface/crud/config.js.map +0 -1
|
@@ -105,21 +105,25 @@ var StackClientInterface = class {
|
|
|
105
105
|
if (!("publishableClientKey" in this.options)) {
|
|
106
106
|
throw new Error("Admin session token is currently not supported for fetching new access token. Did you try to log in on a StackApp initiated with the admin session?");
|
|
107
107
|
}
|
|
108
|
+
const tokenEndpoint = this.getApiUrl() + "/auth/oauth/token";
|
|
108
109
|
const as = {
|
|
109
110
|
issuer: this.options.getBaseUrl(),
|
|
110
111
|
algorithm: "oauth2",
|
|
111
|
-
token_endpoint:
|
|
112
|
+
token_endpoint: tokenEndpoint
|
|
112
113
|
};
|
|
113
114
|
const client = {
|
|
114
115
|
client_id: this.projectId,
|
|
115
|
-
client_secret: this.options.publishableClientKey
|
|
116
|
-
token_endpoint_auth_method: "client_secret_post"
|
|
116
|
+
client_secret: this.options.publishableClientKey
|
|
117
117
|
};
|
|
118
|
+
const clientAuthentication = oauth.ClientSecretPost(this.options.publishableClientKey);
|
|
119
|
+
const allowInsecure = (process.env.NODE_ENV?.includes("dev") || process.env.NODE_ENV === "test") && tokenEndpoint.startsWith("http://");
|
|
118
120
|
const response = await this._networkRetryException(async () => {
|
|
119
121
|
const rawResponse = await oauth.refreshTokenGrantRequest(
|
|
120
122
|
as,
|
|
121
123
|
client,
|
|
122
|
-
|
|
124
|
+
clientAuthentication,
|
|
125
|
+
refreshToken.token,
|
|
126
|
+
allowInsecure ? { [oauth.allowInsecureRequests]: true } : void 0
|
|
123
127
|
);
|
|
124
128
|
const response2 = await this._processResponse(rawResponse);
|
|
125
129
|
if (response2.status === "error") {
|
|
@@ -136,9 +140,18 @@ var StackClientInterface = class {
|
|
|
136
140
|
return response2.data;
|
|
137
141
|
});
|
|
138
142
|
if (!response) return null;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
143
|
+
let result;
|
|
144
|
+
try {
|
|
145
|
+
result = await oauth.processRefreshTokenResponse(as, client, response);
|
|
146
|
+
} catch (e) {
|
|
147
|
+
if (e instanceof oauth.ResponseBodyError) {
|
|
148
|
+
throw new StackAssertionError("ResponseBodyError when processing refresh token response", {
|
|
149
|
+
cause: e.cause,
|
|
150
|
+
code: e.code,
|
|
151
|
+
error: e.error
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
throw new StackAssertionError("Unexpected error when processing refresh token response", { cause: e });
|
|
142
155
|
}
|
|
143
156
|
if (!result.access_token) {
|
|
144
157
|
throw new StackAssertionError("Access token not found in token endpoint response, this is weird!");
|
|
@@ -175,9 +188,9 @@ var StackClientInterface = class {
|
|
|
175
188
|
}
|
|
176
189
|
}
|
|
177
190
|
async sendClientRequestInner(path, options, session, requestType) {
|
|
178
|
-
let tokenObj = await session.getOrFetchLikelyValidTokens(2e4);
|
|
191
|
+
let tokenObj = await session.getOrFetchLikelyValidTokens(2e4, null);
|
|
179
192
|
let adminSession = "projectOwnerSession" in this.options ? this.options.projectOwnerSession : null;
|
|
180
|
-
let adminTokenObj = adminSession ? await adminSession.getOrFetchLikelyValidTokens(2e4) : null;
|
|
193
|
+
let adminTokenObj = adminSession ? await adminSession.getOrFetchLikelyValidTokens(2e4, null) : null;
|
|
181
194
|
await this.options.prepareRequest?.();
|
|
182
195
|
let url = this.getApiUrl() + path;
|
|
183
196
|
if (url.endsWith("/")) {
|
|
@@ -750,7 +763,7 @@ var StackClientInterface = class {
|
|
|
750
763
|
url.searchParams.set("response_type", "code");
|
|
751
764
|
url.searchParams.set("type", options.type);
|
|
752
765
|
url.searchParams.set("error_redirect_url", options.errorRedirectUrl);
|
|
753
|
-
const tokens = await options.session.getOrFetchLikelyValidTokens(
|
|
766
|
+
const tokens = await options.session.getOrFetchLikelyValidTokens(45e3, 6e4);
|
|
754
767
|
if (tokens) {
|
|
755
768
|
url.searchParams.set("token", tokens.accessToken.token);
|
|
756
769
|
}
|
|
@@ -766,35 +779,56 @@ var StackClientInterface = class {
|
|
|
766
779
|
if (!("publishableClientKey" in this.options)) {
|
|
767
780
|
throw new Error("Admin session token is currently not supported for OAuth");
|
|
768
781
|
}
|
|
782
|
+
const tokenEndpoint = this.getApiUrl() + "/auth/oauth/token";
|
|
769
783
|
const as = {
|
|
770
784
|
issuer: this.options.getBaseUrl(),
|
|
771
785
|
algorithm: "oauth2",
|
|
772
|
-
token_endpoint:
|
|
786
|
+
token_endpoint: tokenEndpoint
|
|
773
787
|
};
|
|
774
788
|
const client = {
|
|
775
789
|
client_id: this.projectId,
|
|
776
|
-
client_secret: this.options.publishableClientKey
|
|
777
|
-
token_endpoint_auth_method: "client_secret_post"
|
|
790
|
+
client_secret: this.options.publishableClientKey
|
|
778
791
|
};
|
|
779
|
-
const
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
792
|
+
const clientAuthentication = oauth.ClientSecretPost(this.options.publishableClientKey);
|
|
793
|
+
const allowInsecure = (process.env.NODE_ENV?.includes("dev") || process.env.NODE_ENV === "test") && tokenEndpoint.startsWith("http://");
|
|
794
|
+
let params;
|
|
795
|
+
try {
|
|
796
|
+
params = oauth.validateAuthResponse(as, client, options.oauthParams, options.state);
|
|
797
|
+
} catch (e) {
|
|
798
|
+
if (e instanceof oauth.AuthorizationResponseError) {
|
|
799
|
+
throw new StackAssertionError("Authorization response error when validating outer OAuth response", {
|
|
800
|
+
//cause is a URLSearchParams object for this error, so we need to serialize it better
|
|
801
|
+
cause: Object.fromEntries(e.cause),
|
|
802
|
+
code: e.code,
|
|
803
|
+
error: e.error
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
throw new StackAssertionError("Unexpected error when validating outer OAuth response", { cause: e });
|
|
784
807
|
}
|
|
785
808
|
const response = await oauth.authorizationCodeGrantRequest(
|
|
786
809
|
as,
|
|
787
810
|
client,
|
|
811
|
+
clientAuthentication,
|
|
788
812
|
params,
|
|
789
813
|
options.redirectUri,
|
|
790
|
-
options.codeVerifier
|
|
814
|
+
options.codeVerifier,
|
|
815
|
+
allowInsecure ? { [oauth.allowInsecureRequests]: true } : void 0
|
|
791
816
|
);
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
817
|
+
let result;
|
|
818
|
+
try {
|
|
819
|
+
result = await oauth.processAuthorizationCodeResponse(as, client, response);
|
|
820
|
+
} catch (e) {
|
|
821
|
+
if (e instanceof oauth.ResponseBodyError) {
|
|
822
|
+
if (e.cause.code === "MULTI_FACTOR_AUTHENTICATION_REQUIRED") {
|
|
823
|
+
throw new KnownErrors.MultiFactorAuthenticationRequired(e.cause.details.attempt_code);
|
|
824
|
+
}
|
|
825
|
+
throw new StackAssertionError("Outer OAuth error during authorization code response", {
|
|
826
|
+
cause: e.cause,
|
|
827
|
+
code: e.code,
|
|
828
|
+
error: e.error
|
|
829
|
+
});
|
|
796
830
|
}
|
|
797
|
-
throw new StackAssertionError("
|
|
831
|
+
throw new StackAssertionError("Unexpected error when processing authorization code response", { cause: e });
|
|
798
832
|
}
|
|
799
833
|
return {
|
|
800
834
|
newUser: result.is_new_user,
|
|
@@ -804,7 +838,7 @@ var StackClientInterface = class {
|
|
|
804
838
|
};
|
|
805
839
|
}
|
|
806
840
|
async signOut(session) {
|
|
807
|
-
const tokenObj = await session.getOrFetchLikelyValidTokens(2e4);
|
|
841
|
+
const tokenObj = await session.getOrFetchLikelyValidTokens(2e4, null);
|
|
808
842
|
if (tokenObj) {
|
|
809
843
|
const resOrError = await this.sendClientRequestAndCatchKnownError(
|
|
810
844
|
"/auth/sessions/current",
|
|
@@ -1343,6 +1377,33 @@ var StackClientInterface = class {
|
|
|
1343
1377
|
);
|
|
1344
1378
|
return await response.json();
|
|
1345
1379
|
}
|
|
1380
|
+
async cancelSubscription(options, session) {
|
|
1381
|
+
await this.sendClientRequest(
|
|
1382
|
+
urlString`/payments/products/${options.customer_type}/${options.customer_id}/${options.product_id}`,
|
|
1383
|
+
{
|
|
1384
|
+
method: "DELETE"
|
|
1385
|
+
},
|
|
1386
|
+
session
|
|
1387
|
+
);
|
|
1388
|
+
}
|
|
1389
|
+
async switchSubscription(options, session) {
|
|
1390
|
+
await this.sendClientRequest(
|
|
1391
|
+
urlString`/payments/products/${options.customer_type}/${options.customer_id}/switch`,
|
|
1392
|
+
{
|
|
1393
|
+
method: "POST",
|
|
1394
|
+
headers: {
|
|
1395
|
+
"content-type": "application/json"
|
|
1396
|
+
},
|
|
1397
|
+
body: JSON.stringify({
|
|
1398
|
+
from_product_id: options.from_product_id,
|
|
1399
|
+
to_product_id: options.to_product_id,
|
|
1400
|
+
price_id: options.price_id,
|
|
1401
|
+
quantity: options.quantity
|
|
1402
|
+
})
|
|
1403
|
+
},
|
|
1404
|
+
session
|
|
1405
|
+
);
|
|
1406
|
+
}
|
|
1346
1407
|
async createCheckoutUrl(customer_type, customer_id, productIdOrInline, session, returnUrl) {
|
|
1347
1408
|
const productBody = typeof productIdOrInline === "string" ? { product_id: productIdOrInline } : { inline_product: productIdOrInline };
|
|
1348
1409
|
const response = await this.sendClientRequest(
|
|
@@ -1359,6 +1420,44 @@ var StackClientInterface = class {
|
|
|
1359
1420
|
const { url } = await response.json();
|
|
1360
1421
|
return url;
|
|
1361
1422
|
}
|
|
1423
|
+
async getCustomerBilling(customerType, customerId, session) {
|
|
1424
|
+
const response = await this.sendClientRequest(
|
|
1425
|
+
urlString`/payments/billing/${customerType}/${customerId}`,
|
|
1426
|
+
{},
|
|
1427
|
+
session
|
|
1428
|
+
);
|
|
1429
|
+
return await response.json();
|
|
1430
|
+
}
|
|
1431
|
+
async createCustomerPaymentMethodSetupIntent(customerType, customerId, session) {
|
|
1432
|
+
const response = await this.sendClientRequest(
|
|
1433
|
+
urlString`/payments/payment-method/${customerType}/${customerId}/setup-intent`,
|
|
1434
|
+
{
|
|
1435
|
+
method: "POST",
|
|
1436
|
+
headers: {
|
|
1437
|
+
"content-type": "application/json"
|
|
1438
|
+
},
|
|
1439
|
+
body: JSON.stringify({})
|
|
1440
|
+
},
|
|
1441
|
+
session
|
|
1442
|
+
);
|
|
1443
|
+
return await response.json();
|
|
1444
|
+
}
|
|
1445
|
+
async setDefaultCustomerPaymentMethodFromSetupIntent(customerType, customerId, setupIntentId, session) {
|
|
1446
|
+
const response = await this.sendClientRequest(
|
|
1447
|
+
urlString`/payments/payment-method/${customerType}/${customerId}/set-default`,
|
|
1448
|
+
{
|
|
1449
|
+
method: "POST",
|
|
1450
|
+
headers: {
|
|
1451
|
+
"content-type": "application/json"
|
|
1452
|
+
},
|
|
1453
|
+
body: JSON.stringify({
|
|
1454
|
+
setup_intent_id: setupIntentId
|
|
1455
|
+
})
|
|
1456
|
+
},
|
|
1457
|
+
session
|
|
1458
|
+
);
|
|
1459
|
+
return await response.json();
|
|
1460
|
+
}
|
|
1362
1461
|
async transferProject(internalProjectSession, projectIdToTransfer, newTeamId) {
|
|
1363
1462
|
if (this.options.projectId !== "internal") {
|
|
1364
1463
|
throw new StackAssertionError("StackClientInterface.transferProject() is only available for internal projects (please specify the project ID in the constructor)");
|