@sylphx/sdk 0.21.0 → 0.22.0
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/health/index.d.ts +4 -1
- package/dist/health/index.mjs +1 -0
- package/dist/health/index.mjs.map +1 -1
- package/dist/index.d.ts +86 -96
- package/dist/index.mjs +323 -205
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.ts +40 -66
- package/dist/react/index.mjs +60 -31
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.d.ts +5 -6
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -839,13 +839,13 @@ function createConfigFromComponents(input) {
|
|
|
839
839
|
const env = match[2];
|
|
840
840
|
const slug = resolvedSlug.trim().toLowerCase();
|
|
841
841
|
const domain = input.domain?.trim() || DEFAULT_SDK_API_HOST;
|
|
842
|
-
const
|
|
842
|
+
const baseUrl2 = `https://${slug}.${domain}/v1`;
|
|
843
843
|
return freezeConfig({
|
|
844
844
|
credential: trimmedCred,
|
|
845
845
|
credentialType,
|
|
846
846
|
env,
|
|
847
847
|
slug,
|
|
848
|
-
baseUrl,
|
|
848
|
+
baseUrl: baseUrl2,
|
|
849
849
|
accessToken: input.accessToken
|
|
850
850
|
});
|
|
851
851
|
}
|
|
@@ -856,20 +856,20 @@ function createConfigFromComponents(input) {
|
|
|
856
856
|
const validEnvs = ["dev", "stg", "prod", "prev"];
|
|
857
857
|
const env = validEnvs.includes(envSegment) ? envSegment : "prod";
|
|
858
858
|
const slug = resolvedSlug.trim().toLowerCase();
|
|
859
|
-
let
|
|
859
|
+
let baseUrl2;
|
|
860
860
|
if (input.platformUrl) {
|
|
861
861
|
const platform = input.platformUrl.trim().replace(/\/$/, "");
|
|
862
|
-
|
|
862
|
+
baseUrl2 = platform.includes("/v1") ? platform : `${platform}/v1`;
|
|
863
863
|
} else {
|
|
864
864
|
const domain = input.domain?.trim() || DEFAULT_SDK_API_HOST;
|
|
865
|
-
|
|
865
|
+
baseUrl2 = `https://${slug}.${domain}/v1`;
|
|
866
866
|
}
|
|
867
867
|
return freezeConfig({
|
|
868
868
|
credential: trimmedCred,
|
|
869
869
|
credentialType: prefix,
|
|
870
870
|
env,
|
|
871
871
|
slug,
|
|
872
|
-
baseUrl,
|
|
872
|
+
baseUrl: baseUrl2,
|
|
873
873
|
accessToken: input.accessToken
|
|
874
874
|
});
|
|
875
875
|
}
|
|
@@ -2414,8 +2414,8 @@ async function runPipeline(middlewares, initial) {
|
|
|
2414
2414
|
}
|
|
2415
2415
|
return response;
|
|
2416
2416
|
}
|
|
2417
|
-
function buildUrl(
|
|
2418
|
-
const url = `${
|
|
2417
|
+
function buildUrl(baseUrl2, path, params) {
|
|
2418
|
+
const url = `${baseUrl2}${path}`;
|
|
2419
2419
|
if (!params) return url;
|
|
2420
2420
|
const entries = Object.entries(params).filter(([, v]) => v !== void 0);
|
|
2421
2421
|
if (entries.length === 0) return url;
|
|
@@ -2437,9 +2437,9 @@ function interpolatePath(path, pathParams) {
|
|
|
2437
2437
|
return encodeURIComponent(value);
|
|
2438
2438
|
});
|
|
2439
2439
|
}
|
|
2440
|
-
async function executeRequest(method,
|
|
2440
|
+
async function executeRequest(method, baseUrl2, path, options, baseHeaders, middlewares) {
|
|
2441
2441
|
const finalPath = interpolatePath(path, options?.params?.path);
|
|
2442
|
-
const url = buildUrl(
|
|
2442
|
+
const url = buildUrl(baseUrl2, finalPath, options?.params?.query);
|
|
2443
2443
|
const headers = { ...baseHeaders, ...options?.headers };
|
|
2444
2444
|
const init = { method, headers };
|
|
2445
2445
|
if (options?.body !== void 0) {
|
|
@@ -2471,9 +2471,9 @@ async function executeRequest(method, baseUrl, path, options, baseHeaders, middl
|
|
|
2471
2471
|
}
|
|
2472
2472
|
return { error: parsed, response };
|
|
2473
2473
|
}
|
|
2474
|
-
function buildClient(
|
|
2474
|
+
function buildClient(baseUrl2, baseHeaders) {
|
|
2475
2475
|
const middlewares = [];
|
|
2476
|
-
const dispatch = (method) => (path, options) => executeRequest(method,
|
|
2476
|
+
const dispatch = (method) => (path, options) => executeRequest(method, baseUrl2, path, options, baseHeaders, middlewares);
|
|
2477
2477
|
const client = {
|
|
2478
2478
|
GET: dispatch("GET"),
|
|
2479
2479
|
POST: dispatch("POST"),
|
|
@@ -2816,8 +2816,8 @@ function validateClientConfig(config) {
|
|
|
2816
2816
|
};
|
|
2817
2817
|
}
|
|
2818
2818
|
function createRestClient(config) {
|
|
2819
|
-
const { secretKey, baseUrl } = validateClientConfig(config);
|
|
2820
|
-
const { client, middlewares } = buildClient(`${
|
|
2819
|
+
const { secretKey, baseUrl: baseUrl2 } = validateClientConfig(config);
|
|
2820
|
+
const { client, middlewares } = buildClient(`${baseUrl2}${SDK_API_PATH}`, {
|
|
2821
2821
|
"Content-Type": "application/json",
|
|
2822
2822
|
"x-app-secret": secretKey
|
|
2823
2823
|
});
|
|
@@ -2834,13 +2834,13 @@ function createRestClient(config) {
|
|
|
2834
2834
|
return client;
|
|
2835
2835
|
}
|
|
2836
2836
|
function createDynamicRestClient(config) {
|
|
2837
|
-
const { secretKey, baseUrl } = validateClientConfig(config);
|
|
2837
|
+
const { secretKey, baseUrl: baseUrl2 } = validateClientConfig(config);
|
|
2838
2838
|
const validatedConfig = {
|
|
2839
2839
|
...config,
|
|
2840
2840
|
secretKey,
|
|
2841
|
-
platformUrl:
|
|
2841
|
+
platformUrl: baseUrl2
|
|
2842
2842
|
};
|
|
2843
|
-
const { client, middlewares } = buildClient(`${
|
|
2843
|
+
const { client, middlewares } = buildClient(`${baseUrl2}${SDK_API_PATH}`, {
|
|
2844
2844
|
"Content-Type": "application/json"
|
|
2845
2845
|
});
|
|
2846
2846
|
if (config.deduplication !== false) {
|
|
@@ -2874,7 +2874,7 @@ function getRestErrorMessage(error) {
|
|
|
2874
2874
|
init_errors();
|
|
2875
2875
|
|
|
2876
2876
|
// src/auth.ts
|
|
2877
|
-
import { authEndpoints } from "@sylphx/contract";
|
|
2877
|
+
import { authEndpoints as authEndpoints4 } from "@sylphx/contract";
|
|
2878
2878
|
|
|
2879
2879
|
// src/dpop.ts
|
|
2880
2880
|
var dpop = {
|
|
@@ -2964,15 +2964,37 @@ function randomJti() {
|
|
|
2964
2964
|
return base64UrlEncode(bytes);
|
|
2965
2965
|
}
|
|
2966
2966
|
|
|
2967
|
+
// src/platform-auth.ts
|
|
2968
|
+
import { authEndpoints, refreshEndpoints } from "@sylphx/contract";
|
|
2969
|
+
|
|
2970
|
+
// src/contract-http.ts
|
|
2971
|
+
function baseUrl(url) {
|
|
2972
|
+
return url.replace(/\/$/, "");
|
|
2973
|
+
}
|
|
2974
|
+
function interpolatePath2(template, params) {
|
|
2975
|
+
let path = template;
|
|
2976
|
+
for (const [key, value] of Object.entries(params)) {
|
|
2977
|
+
path = path.replace(`:${key}`, encodeURIComponent(value));
|
|
2978
|
+
}
|
|
2979
|
+
return path;
|
|
2980
|
+
}
|
|
2981
|
+
function buildEndpointUrl(base, path, query) {
|
|
2982
|
+
const url = new URL(`${baseUrl(base)}${path}`);
|
|
2983
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
2984
|
+
if (value !== void 0) url.searchParams.set(key, value);
|
|
2985
|
+
}
|
|
2986
|
+
return url.toString();
|
|
2987
|
+
}
|
|
2988
|
+
|
|
2967
2989
|
// src/platform-auth.ts
|
|
2968
2990
|
init_errors();
|
|
2969
2991
|
var platformAuth = {
|
|
2970
2992
|
async refresh(opts) {
|
|
2971
2993
|
const headers = { "Content-Type": "application/json" };
|
|
2972
2994
|
if (opts.userAgent) headers["User-Agent"] = opts.userAgent;
|
|
2973
|
-
const
|
|
2974
|
-
const res = await fetch(
|
|
2975
|
-
method:
|
|
2995
|
+
const endpoint = refreshEndpoints.refresh;
|
|
2996
|
+
const res = await fetch(platformAuthEndpointUrl(opts, endpoint.path), {
|
|
2997
|
+
method: endpoint.method,
|
|
2976
2998
|
headers,
|
|
2977
2999
|
body: JSON.stringify({ refresh_token: opts.refreshToken })
|
|
2978
3000
|
});
|
|
@@ -2982,15 +3004,19 @@ var platformAuth = {
|
|
|
2982
3004
|
async logout(opts) {
|
|
2983
3005
|
const headers = { "Content-Type": "application/json" };
|
|
2984
3006
|
if (opts.userAgent) headers["User-Agent"] = opts.userAgent;
|
|
2985
|
-
const
|
|
2986
|
-
const res = await fetch(
|
|
2987
|
-
method:
|
|
3007
|
+
const endpoint = authEndpoints.signOut;
|
|
3008
|
+
const res = await fetch(platformAuthEndpointUrl(opts, endpoint.path), {
|
|
3009
|
+
method: endpoint.method,
|
|
2988
3010
|
headers,
|
|
2989
3011
|
body: JSON.stringify({ refresh_token: opts.refreshToken })
|
|
2990
3012
|
});
|
|
2991
3013
|
if (!res.ok) throw await platformAuthError(res, "platformAuth.logout");
|
|
2992
3014
|
}
|
|
2993
3015
|
};
|
|
3016
|
+
function platformAuthEndpointUrl(opts, path) {
|
|
3017
|
+
const prefix = opts.urlPrefix ?? "/api/v1";
|
|
3018
|
+
return buildEndpointUrl(`${opts.baseUrl.replace(/\/$/, "")}${prefix}`, path);
|
|
3019
|
+
}
|
|
2994
3020
|
async function platformAuthError(res, operation) {
|
|
2995
3021
|
const body = await res.text().catch(() => "");
|
|
2996
3022
|
let code = "platform_auth_error";
|
|
@@ -3183,10 +3209,10 @@ function resetPlatformJwksCache() {
|
|
|
3183
3209
|
jwtJwksCache = null;
|
|
3184
3210
|
}
|
|
3185
3211
|
var PLATFORM_JWKS_TTL_MS = 60 * 60 * 1e3;
|
|
3186
|
-
async function fetchPlatformJwks(
|
|
3212
|
+
async function fetchPlatformJwks(baseUrl2) {
|
|
3187
3213
|
const now = Date.now();
|
|
3188
3214
|
if (jwtJwksCache && jwtJwksCache.expiresAt > now) return jwtJwksCache.keys;
|
|
3189
|
-
const root =
|
|
3215
|
+
const root = baseUrl2.replace(/\/$/, "").replace(/\/v1$/, "");
|
|
3190
3216
|
const res = await fetch(`${root}/.well-known/jwks.json`);
|
|
3191
3217
|
if (!res.ok) throw new Error(`JWKS fetch failed: HTTP ${res.status}`);
|
|
3192
3218
|
const data = await res.json();
|
|
@@ -3596,19 +3622,22 @@ async function platformJwtError(res, operation) {
|
|
|
3596
3622
|
}
|
|
3597
3623
|
|
|
3598
3624
|
// src/platform-password.ts
|
|
3625
|
+
import { authEndpoints as authEndpoints2 } from "@sylphx/contract";
|
|
3599
3626
|
init_errors();
|
|
3600
3627
|
var password = {
|
|
3601
3628
|
async status(opts) {
|
|
3602
|
-
const
|
|
3603
|
-
|
|
3629
|
+
const endpoint = authEndpoints2.platformPasswordStatus;
|
|
3630
|
+
const res = await fetch(buildEndpointUrl(opts.baseUrl, endpoint.path), {
|
|
3631
|
+
method: endpoint.method,
|
|
3604
3632
|
headers: buildPlatformPasswordHeaders(opts.accessToken, opts.userAgent)
|
|
3605
3633
|
});
|
|
3606
3634
|
if (!res.ok) throw await platformPasswordError(res, "password.status");
|
|
3607
3635
|
return await res.json();
|
|
3608
3636
|
},
|
|
3609
3637
|
async set(opts) {
|
|
3610
|
-
const
|
|
3611
|
-
|
|
3638
|
+
const endpoint = authEndpoints2.platformPasswordSet;
|
|
3639
|
+
const res = await fetch(buildEndpointUrl(opts.baseUrl, endpoint.path), {
|
|
3640
|
+
method: endpoint.method,
|
|
3612
3641
|
headers: buildPlatformPasswordHeaders(opts.accessToken, opts.userAgent),
|
|
3613
3642
|
body: JSON.stringify({
|
|
3614
3643
|
password: opts.password
|
|
@@ -3618,8 +3647,9 @@ var password = {
|
|
|
3618
3647
|
return await res.json();
|
|
3619
3648
|
},
|
|
3620
3649
|
async change(opts) {
|
|
3621
|
-
const
|
|
3622
|
-
|
|
3650
|
+
const endpoint = authEndpoints2.platformPasswordChange;
|
|
3651
|
+
const res = await fetch(buildEndpointUrl(opts.baseUrl, endpoint.path), {
|
|
3652
|
+
method: endpoint.method,
|
|
3623
3653
|
headers: buildPlatformPasswordHeaders(opts.accessToken, opts.userAgent),
|
|
3624
3654
|
body: JSON.stringify({
|
|
3625
3655
|
currentPassword: opts.currentPassword,
|
|
@@ -3663,19 +3693,22 @@ async function platformPasswordError(res, operation) {
|
|
|
3663
3693
|
}
|
|
3664
3694
|
|
|
3665
3695
|
// src/platform-sessions.ts
|
|
3696
|
+
import { authEndpoints as authEndpoints3 } from "@sylphx/contract";
|
|
3666
3697
|
init_errors();
|
|
3667
3698
|
var sessions = {
|
|
3668
3699
|
async list(opts) {
|
|
3669
|
-
const
|
|
3670
|
-
|
|
3700
|
+
const endpoint = authEndpoints3.platformSessionsList;
|
|
3701
|
+
const res = await fetch(buildEndpointUrl(opts.baseUrl, endpoint.path), {
|
|
3702
|
+
method: endpoint.method,
|
|
3671
3703
|
headers: buildPlatformSessionsHeaders(opts.accessToken, opts.userAgent)
|
|
3672
3704
|
});
|
|
3673
3705
|
if (!res.ok) throw await platformSessionError(res, "sessions.list");
|
|
3674
3706
|
return await res.json();
|
|
3675
3707
|
},
|
|
3676
3708
|
async revoke(opts) {
|
|
3677
|
-
const
|
|
3678
|
-
|
|
3709
|
+
const endpoint = authEndpoints3.platformSessionsRevoke;
|
|
3710
|
+
const res = await fetch(buildEndpointUrl(opts.baseUrl, endpoint.path), {
|
|
3711
|
+
method: endpoint.method,
|
|
3679
3712
|
headers: buildPlatformSessionsHeaders(opts.accessToken, opts.userAgent),
|
|
3680
3713
|
body: JSON.stringify({ sessionId: opts.sessionId })
|
|
3681
3714
|
});
|
|
@@ -3683,30 +3716,27 @@ var sessions = {
|
|
|
3683
3716
|
return await res.json();
|
|
3684
3717
|
},
|
|
3685
3718
|
async revokeOther(opts) {
|
|
3686
|
-
const
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
}
|
|
3692
|
-
);
|
|
3719
|
+
const endpoint = authEndpoints3.platformSessionsRevokeOther;
|
|
3720
|
+
const res = await fetch(buildEndpointUrl(opts.baseUrl, endpoint.path), {
|
|
3721
|
+
method: endpoint.method,
|
|
3722
|
+
headers: buildPlatformSessionsHeaders(opts.accessToken, opts.userAgent)
|
|
3723
|
+
});
|
|
3693
3724
|
if (!res.ok) throw await platformSessionError(res, "sessions.revokeOther");
|
|
3694
3725
|
return await res.json();
|
|
3695
3726
|
},
|
|
3696
3727
|
async revokeAll(opts) {
|
|
3697
|
-
const
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
}
|
|
3703
|
-
);
|
|
3728
|
+
const endpoint = authEndpoints3.platformSessionsRevokeAll;
|
|
3729
|
+
const res = await fetch(buildEndpointUrl(opts.baseUrl, endpoint.path), {
|
|
3730
|
+
method: endpoint.method,
|
|
3731
|
+
headers: buildPlatformSessionsHeaders(opts.accessToken, opts.userAgent)
|
|
3732
|
+
});
|
|
3704
3733
|
if (!res.ok) throw await platformSessionError(res, "sessions.revokeAll");
|
|
3705
3734
|
return await res.json();
|
|
3706
3735
|
},
|
|
3707
3736
|
async rename(opts) {
|
|
3708
|
-
const
|
|
3709
|
-
|
|
3737
|
+
const endpoint = authEndpoints3.platformSessionsRename;
|
|
3738
|
+
const res = await fetch(buildEndpointUrl(opts.baseUrl, endpoint.path), {
|
|
3739
|
+
method: endpoint.method,
|
|
3710
3740
|
headers: buildPlatformSessionsHeaders(opts.accessToken, opts.userAgent),
|
|
3711
3741
|
body: JSON.stringify({
|
|
3712
3742
|
sessionId: opts.sessionId,
|
|
@@ -3904,21 +3934,21 @@ async function signInAsService(config, credentials) {
|
|
|
3904
3934
|
// src/auth.ts
|
|
3905
3935
|
async function signIn(config, input) {
|
|
3906
3936
|
const body = input;
|
|
3907
|
-
const endpoint =
|
|
3937
|
+
const endpoint = authEndpoints4.signIn;
|
|
3908
3938
|
return callApi(config, endpoint.path, {
|
|
3909
3939
|
method: endpoint.method,
|
|
3910
3940
|
body
|
|
3911
3941
|
});
|
|
3912
3942
|
}
|
|
3913
3943
|
async function signUp(config, input) {
|
|
3914
|
-
const endpoint =
|
|
3944
|
+
const endpoint = authEndpoints4.signUp;
|
|
3915
3945
|
return callApi(config, endpoint.path, {
|
|
3916
3946
|
method: endpoint.method,
|
|
3917
3947
|
body: input
|
|
3918
3948
|
});
|
|
3919
3949
|
}
|
|
3920
3950
|
async function signOut(config) {
|
|
3921
|
-
const endpoint =
|
|
3951
|
+
const endpoint = authEndpoints4.signOut;
|
|
3922
3952
|
await callApi(config, endpoint.path, { method: endpoint.method });
|
|
3923
3953
|
}
|
|
3924
3954
|
async function refreshToken(config, token) {
|
|
@@ -3947,7 +3977,7 @@ async function forgotPassword(config, email, options = {}) {
|
|
|
3947
3977
|
});
|
|
3948
3978
|
}
|
|
3949
3979
|
async function resendVerificationEmail(config, email) {
|
|
3950
|
-
const endpoint =
|
|
3980
|
+
const endpoint = authEndpoints4.resendEmailVerification;
|
|
3951
3981
|
const body = { email };
|
|
3952
3982
|
await callApi(config, endpoint.path, {
|
|
3953
3983
|
method: endpoint.method,
|
|
@@ -3964,7 +3994,7 @@ async function getSession(config) {
|
|
|
3964
3994
|
if (!config.accessToken) {
|
|
3965
3995
|
return { user: null };
|
|
3966
3996
|
}
|
|
3967
|
-
const endpoint =
|
|
3997
|
+
const endpoint = authEndpoints4.getSession;
|
|
3968
3998
|
try {
|
|
3969
3999
|
const user2 = await callApi(config, endpoint.path, {
|
|
3970
4000
|
method: endpoint.method
|
|
@@ -4159,6 +4189,7 @@ async function deviceError(res, operation) {
|
|
|
4159
4189
|
}
|
|
4160
4190
|
|
|
4161
4191
|
// src/audit.ts
|
|
4192
|
+
import { auditEndpoints } from "@sylphx/contract";
|
|
4162
4193
|
function buildHeaders2(accessToken, userAgent) {
|
|
4163
4194
|
const headers = {
|
|
4164
4195
|
Accept: "application/json",
|
|
@@ -4193,19 +4224,21 @@ async function auditError(res, operation) {
|
|
|
4193
4224
|
}
|
|
4194
4225
|
var audit = {
|
|
4195
4226
|
async query(opts) {
|
|
4196
|
-
const
|
|
4227
|
+
const endpoint = auditEndpoints.query;
|
|
4197
4228
|
const f = opts.filter ?? {};
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4229
|
+
const url = buildEndpointUrl(opts.baseUrl, endpoint.path, {
|
|
4230
|
+
scope: f.scope,
|
|
4231
|
+
actor: f.actor,
|
|
4232
|
+
resource_type: f.resourceType,
|
|
4233
|
+
resource_id: f.resourceId,
|
|
4234
|
+
action: f.action,
|
|
4235
|
+
from: f.from,
|
|
4236
|
+
to: f.to,
|
|
4237
|
+
cursor: f.cursor,
|
|
4238
|
+
limit: f.limit === void 0 ? void 0 : String(f.limit)
|
|
4239
|
+
});
|
|
4240
|
+
const res = await fetch(url, {
|
|
4241
|
+
method: endpoint.method,
|
|
4209
4242
|
headers: buildHeaders2(opts.accessToken, opts.userAgent)
|
|
4210
4243
|
});
|
|
4211
4244
|
if (!res.ok) throw await auditError(res, "audit.query");
|
|
@@ -4214,6 +4247,7 @@ var audit = {
|
|
|
4214
4247
|
};
|
|
4215
4248
|
|
|
4216
4249
|
// src/rate-limits.ts
|
|
4250
|
+
import { rateLimitsEndpoints } from "@sylphx/contract";
|
|
4217
4251
|
function buildHeaders3(accessToken, userAgent) {
|
|
4218
4252
|
const headers = {
|
|
4219
4253
|
Accept: "application/json",
|
|
@@ -4249,54 +4283,74 @@ async function rateLimitError(res, operation) {
|
|
|
4249
4283
|
}
|
|
4250
4284
|
var rateLimits = {
|
|
4251
4285
|
async status(opts) {
|
|
4252
|
-
const
|
|
4286
|
+
const endpoint = rateLimitsEndpoints.status;
|
|
4253
4287
|
const f = opts.filter ?? {};
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4288
|
+
const res = await fetch(
|
|
4289
|
+
buildEndpointUrl(opts.baseUrl, endpoint.path, {
|
|
4290
|
+
scope: f.scope,
|
|
4291
|
+
scope_id: f.scope_id,
|
|
4292
|
+
namespace: f.namespace
|
|
4293
|
+
}),
|
|
4294
|
+
{
|
|
4295
|
+
method: endpoint.method,
|
|
4296
|
+
headers: buildHeaders3(opts.accessToken, opts.userAgent)
|
|
4297
|
+
}
|
|
4298
|
+
);
|
|
4261
4299
|
if (!res.ok) throw await rateLimitError(res, "rateLimits.status");
|
|
4262
4300
|
return await res.json();
|
|
4263
4301
|
},
|
|
4264
4302
|
strategies: {
|
|
4265
4303
|
async list(opts) {
|
|
4266
|
-
const
|
|
4304
|
+
const endpoint = rateLimitsEndpoints.strategiesList;
|
|
4267
4305
|
const f = opts.filter ?? {};
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4306
|
+
const res = await fetch(
|
|
4307
|
+
buildEndpointUrl(opts.baseUrl, endpoint.path, {
|
|
4308
|
+
scope: f.scope,
|
|
4309
|
+
scope_id: f.scope_id
|
|
4310
|
+
}),
|
|
4311
|
+
{
|
|
4312
|
+
method: endpoint.method,
|
|
4313
|
+
headers: buildHeaders3(opts.accessToken, opts.userAgent)
|
|
4314
|
+
}
|
|
4315
|
+
);
|
|
4274
4316
|
if (!res.ok) throw await rateLimitError(res, "rateLimits.strategies.list");
|
|
4275
4317
|
return await res.json();
|
|
4276
4318
|
},
|
|
4277
4319
|
async set(opts) {
|
|
4278
|
-
const
|
|
4279
|
-
const res = await fetch(
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4320
|
+
const endpoint = rateLimitsEndpoints.strategyUpsert;
|
|
4321
|
+
const res = await fetch(
|
|
4322
|
+
buildEndpointUrl(
|
|
4323
|
+
opts.baseUrl,
|
|
4324
|
+
interpolatePath2(endpoint.path, { namespace: opts.namespace })
|
|
4325
|
+
),
|
|
4326
|
+
{
|
|
4327
|
+
method: endpoint.method,
|
|
4328
|
+
headers: {
|
|
4329
|
+
...buildHeaders3(opts.accessToken, opts.userAgent),
|
|
4330
|
+
"content-type": "application/json"
|
|
4331
|
+
},
|
|
4332
|
+
body: JSON.stringify(opts.body)
|
|
4333
|
+
}
|
|
4334
|
+
);
|
|
4287
4335
|
if (!res.ok) throw await rateLimitError(res, "rateLimits.strategies.set");
|
|
4288
4336
|
return await res.json();
|
|
4289
4337
|
},
|
|
4290
4338
|
async delete(opts) {
|
|
4291
|
-
const
|
|
4292
|
-
const res = await fetch(
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4339
|
+
const endpoint = rateLimitsEndpoints.strategyDelete;
|
|
4340
|
+
const res = await fetch(
|
|
4341
|
+
buildEndpointUrl(
|
|
4342
|
+
opts.baseUrl,
|
|
4343
|
+
interpolatePath2(endpoint.path, { namespace: opts.namespace })
|
|
4344
|
+
),
|
|
4345
|
+
{
|
|
4346
|
+
method: endpoint.method,
|
|
4347
|
+
headers: {
|
|
4348
|
+
...buildHeaders3(opts.accessToken, opts.userAgent),
|
|
4349
|
+
"content-type": "application/json"
|
|
4350
|
+
},
|
|
4351
|
+
body: JSON.stringify(opts.body)
|
|
4352
|
+
}
|
|
4353
|
+
);
|
|
4300
4354
|
if (!res.ok) throw await rateLimitError(res, "rateLimits.strategies.delete");
|
|
4301
4355
|
return await res.json();
|
|
4302
4356
|
}
|
|
@@ -4813,6 +4867,7 @@ async function getBillingUsage(config, options) {
|
|
|
4813
4867
|
}
|
|
4814
4868
|
|
|
4815
4869
|
// src/storage.ts
|
|
4870
|
+
import { storageEndpoints } from "@sylphx/contract";
|
|
4816
4871
|
init_errors();
|
|
4817
4872
|
|
|
4818
4873
|
// src/lib/retry.ts
|
|
@@ -4925,18 +4980,24 @@ function randomBytes(n) {
|
|
|
4925
4980
|
|
|
4926
4981
|
// src/storage.ts
|
|
4927
4982
|
var PATHS = {
|
|
4928
|
-
uploads:
|
|
4929
|
-
upload: (id) =>
|
|
4930
|
-
uploadComplete: (id) =>
|
|
4931
|
-
uploadPart: (id, n) =>
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4983
|
+
uploads: storageEndpoints.createUpload.path,
|
|
4984
|
+
upload: (id) => interpolatePath2(storageEndpoints.abortUpload.path, { uploadId: String(id) }),
|
|
4985
|
+
uploadComplete: (id) => interpolatePath2(storageEndpoints.completeUpload.path, { uploadId: String(id) }),
|
|
4986
|
+
uploadPart: (id, n) => interpolatePath2(storageEndpoints.presignUploadPart.path, {
|
|
4987
|
+
uploadId: String(id),
|
|
4988
|
+
partNumber: String(n)
|
|
4989
|
+
}),
|
|
4990
|
+
files: storageEndpoints.listFiles.path,
|
|
4991
|
+
file: (id) => interpolatePath2(storageEndpoints.getFile.path, { fileId: String(id) }),
|
|
4992
|
+
fileTakedown: (id) => interpolatePath2(storageEndpoints.takedownFile.path, { fileId: String(id) }),
|
|
4993
|
+
fileRestore: (id) => interpolatePath2(storageEndpoints.restoreFile.path, { fileId: String(id) }),
|
|
4994
|
+
fileSignedUrl: (id) => interpolatePath2(storageEndpoints.signFileUrl.path, { fileId: String(id) }),
|
|
4995
|
+
fileCopy: (id) => interpolatePath2(storageEndpoints.copyFile.path, { fileId: String(id) }),
|
|
4996
|
+
versions: (id) => interpolatePath2(storageEndpoints.listFileVersions.path, { fileId: String(id) }),
|
|
4997
|
+
versionRestore: (id, vid) => interpolatePath2(storageEndpoints.restoreFileVersion.path, {
|
|
4998
|
+
fileId: String(id),
|
|
4999
|
+
versionId: String(vid)
|
|
5000
|
+
})
|
|
4940
5001
|
};
|
|
4941
5002
|
var hasXhr = () => typeof globalThis.XMLHttpRequest !== "undefined";
|
|
4942
5003
|
var hasLocalStorage = () => {
|
|
@@ -5134,7 +5195,7 @@ async function uploadsCreate(config, blob, options) {
|
|
|
5134
5195
|
ifNoneMatch: options.ifNoneMatch
|
|
5135
5196
|
};
|
|
5136
5197
|
const session = await callApi(config, PATHS.uploads, {
|
|
5137
|
-
method:
|
|
5198
|
+
method: storageEndpoints.createUpload.method,
|
|
5138
5199
|
body: createBody,
|
|
5139
5200
|
idempotencyKey,
|
|
5140
5201
|
signal
|
|
@@ -5142,7 +5203,7 @@ async function uploadsCreate(config, blob, options) {
|
|
|
5142
5203
|
const uploadId = session.uploadId;
|
|
5143
5204
|
const onAborted = async () => {
|
|
5144
5205
|
try {
|
|
5145
|
-
await callApi(config, PATHS.upload(uploadId), { method:
|
|
5206
|
+
await callApi(config, PATHS.upload(uploadId), { method: storageEndpoints.abortUpload.method });
|
|
5146
5207
|
} catch {
|
|
5147
5208
|
}
|
|
5148
5209
|
clearResume(String(uploadId));
|
|
@@ -5174,7 +5235,7 @@ async function runSinglePart(config, blob, session, options, idempotencyKey) {
|
|
|
5174
5235
|
config,
|
|
5175
5236
|
PATHS.uploadComplete(session.uploadId),
|
|
5176
5237
|
{
|
|
5177
|
-
method:
|
|
5238
|
+
method: storageEndpoints.completeUpload.method,
|
|
5178
5239
|
body: { parts: [{ partNumber: 1, etag: put.etag }] },
|
|
5179
5240
|
idempotencyKey: `${idempotencyKey}:complete`,
|
|
5180
5241
|
signal
|
|
@@ -5219,7 +5280,7 @@ async function runMultipart(config, blob, session, options, idempotencyKey) {
|
|
|
5219
5280
|
config,
|
|
5220
5281
|
PATHS.uploadComplete(session.uploadId),
|
|
5221
5282
|
{
|
|
5222
|
-
method:
|
|
5283
|
+
method: storageEndpoints.completeUpload.method,
|
|
5223
5284
|
body: { parts: completedParts },
|
|
5224
5285
|
idempotencyKey: `${idempotencyKey}:complete`,
|
|
5225
5286
|
signal
|
|
@@ -5229,9 +5290,12 @@ async function runMultipart(config, blob, session, options, idempotencyKey) {
|
|
|
5229
5290
|
return fileFromCompletion(completion, options, blob);
|
|
5230
5291
|
}
|
|
5231
5292
|
async function uploadsAbort(config, uploadId) {
|
|
5232
|
-
await withRetry(
|
|
5233
|
-
|
|
5234
|
-
|
|
5293
|
+
await withRetry(
|
|
5294
|
+
() => callApi(config, PATHS.upload(uploadId), { method: storageEndpoints.abortUpload.method }),
|
|
5295
|
+
{
|
|
5296
|
+
maxRetries: 3
|
|
5297
|
+
}
|
|
5298
|
+
);
|
|
5235
5299
|
clearResume(String(uploadId));
|
|
5236
5300
|
}
|
|
5237
5301
|
function filesListPage(config, options, cursor) {
|
|
@@ -5242,7 +5306,7 @@ function filesListPage(config, options, cursor) {
|
|
|
5242
5306
|
includeDeleted: options.includeDeleted
|
|
5243
5307
|
};
|
|
5244
5308
|
return callApi(config, PATHS.files, {
|
|
5245
|
-
method:
|
|
5309
|
+
method: storageEndpoints.listFiles.method,
|
|
5246
5310
|
query: {
|
|
5247
5311
|
folder: query.folder,
|
|
5248
5312
|
cursor: query.cursor,
|
|
@@ -5266,19 +5330,23 @@ function filesList(config, options = {}) {
|
|
|
5266
5330
|
return Object.assign(iter, { fetchPage });
|
|
5267
5331
|
}
|
|
5268
5332
|
async function filesGet(config, fileId) {
|
|
5269
|
-
return callApi(config, PATHS.file(fileId), {
|
|
5333
|
+
return callApi(config, PATHS.file(fileId), {
|
|
5334
|
+
method: storageEndpoints.getFile.method
|
|
5335
|
+
});
|
|
5270
5336
|
}
|
|
5271
5337
|
async function filesDelete(config, fileId) {
|
|
5272
|
-
return callApi(config, PATHS.file(fileId), { method:
|
|
5338
|
+
return callApi(config, PATHS.file(fileId), { method: storageEndpoints.deleteFile.method });
|
|
5273
5339
|
}
|
|
5274
5340
|
async function filesTakedown(config, fileId, options) {
|
|
5275
5341
|
return callApi(config, PATHS.fileTakedown(fileId), {
|
|
5276
|
-
method:
|
|
5342
|
+
method: storageEndpoints.takedownFile.method,
|
|
5277
5343
|
body: options
|
|
5278
5344
|
});
|
|
5279
5345
|
}
|
|
5280
5346
|
async function filesRestore(config, fileId) {
|
|
5281
|
-
return callApi(config, PATHS.fileRestore(fileId), {
|
|
5347
|
+
return callApi(config, PATHS.fileRestore(fileId), {
|
|
5348
|
+
method: storageEndpoints.restoreFile.method
|
|
5349
|
+
});
|
|
5282
5350
|
}
|
|
5283
5351
|
async function filesSignedUrl(config, fileId, options = {}) {
|
|
5284
5352
|
const body = {
|
|
@@ -5287,7 +5355,7 @@ async function filesSignedUrl(config, fileId, options = {}) {
|
|
|
5287
5355
|
userId: options.userId
|
|
5288
5356
|
};
|
|
5289
5357
|
return callApi(config, PATHS.fileSignedUrl(fileId), {
|
|
5290
|
-
method:
|
|
5358
|
+
method: storageEndpoints.signFileUrl.method,
|
|
5291
5359
|
body
|
|
5292
5360
|
});
|
|
5293
5361
|
}
|
|
@@ -5299,18 +5367,20 @@ async function filesCopy(config, fileId, options) {
|
|
|
5299
5367
|
metadata: options.metadata
|
|
5300
5368
|
};
|
|
5301
5369
|
return callApi(config, PATHS.fileCopy(fileId), {
|
|
5302
|
-
method:
|
|
5370
|
+
method: storageEndpoints.copyFile.method,
|
|
5303
5371
|
body
|
|
5304
5372
|
});
|
|
5305
5373
|
}
|
|
5306
5374
|
async function filesVersionsList(config, fileId) {
|
|
5307
5375
|
const data = await callApi(config, PATHS.versions(fileId), {
|
|
5308
|
-
method:
|
|
5376
|
+
method: storageEndpoints.listFileVersions.method
|
|
5309
5377
|
});
|
|
5310
5378
|
return data.versions;
|
|
5311
5379
|
}
|
|
5312
5380
|
async function filesVersionsRestore(config, fileId, versionId) {
|
|
5313
|
-
return callApi(config, PATHS.versionRestore(fileId, versionId), {
|
|
5381
|
+
return callApi(config, PATHS.versionRestore(fileId, versionId), {
|
|
5382
|
+
method: storageEndpoints.restoreFileVersion.method
|
|
5383
|
+
});
|
|
5314
5384
|
}
|
|
5315
5385
|
var storage = {
|
|
5316
5386
|
uploads: {
|
|
@@ -5484,6 +5554,7 @@ async function registerPushServiceWorker(swPath = "/sw.js") {
|
|
|
5484
5554
|
}
|
|
5485
5555
|
|
|
5486
5556
|
// src/notifications.ts
|
|
5557
|
+
import { notificationsEndpoints } from "@sylphx/contract";
|
|
5487
5558
|
function resolveSentCount(result) {
|
|
5488
5559
|
if (result.sent !== void 0) return result.sent;
|
|
5489
5560
|
if (result.sentTo !== void 0) return result.sentTo;
|
|
@@ -5495,14 +5566,16 @@ function resolveFailedCount(result) {
|
|
|
5495
5566
|
return result.status === "failed" ? 1 : 0;
|
|
5496
5567
|
}
|
|
5497
5568
|
async function registerPush(config, subscription) {
|
|
5498
|
-
|
|
5499
|
-
|
|
5569
|
+
const endpoint = notificationsEndpoints.registerPush;
|
|
5570
|
+
await callApi(config, endpoint.path, {
|
|
5571
|
+
method: endpoint.method,
|
|
5500
5572
|
body: { subscription }
|
|
5501
5573
|
});
|
|
5502
5574
|
}
|
|
5503
5575
|
async function unregisterPush(config, endpoint) {
|
|
5504
|
-
|
|
5505
|
-
|
|
5576
|
+
const route = notificationsEndpoints.unregisterPush;
|
|
5577
|
+
await callApi(config, route.path, {
|
|
5578
|
+
method: route.method,
|
|
5506
5579
|
body: { endpoint }
|
|
5507
5580
|
});
|
|
5508
5581
|
}
|
|
@@ -5514,8 +5587,9 @@ async function sendPush(config, userId, notification) {
|
|
|
5514
5587
|
...notification.icon !== void 0 && { icon: notification.icon },
|
|
5515
5588
|
...notification.url !== void 0 && { url: notification.url }
|
|
5516
5589
|
};
|
|
5517
|
-
const
|
|
5518
|
-
|
|
5590
|
+
const endpoint = notificationsEndpoints.sendPush;
|
|
5591
|
+
const result = await callApi(config, endpoint.path, {
|
|
5592
|
+
method: endpoint.method,
|
|
5519
5593
|
body
|
|
5520
5594
|
});
|
|
5521
5595
|
const sent = resolveSentCount(result);
|
|
@@ -5529,49 +5603,61 @@ async function sendPush(config, userId, notification) {
|
|
|
5529
5603
|
};
|
|
5530
5604
|
}
|
|
5531
5605
|
async function getPushPreferences(config) {
|
|
5532
|
-
|
|
5606
|
+
const endpoint = notificationsEndpoints.getPreferences;
|
|
5607
|
+
return callApi(config, endpoint.path, { method: endpoint.method });
|
|
5533
5608
|
}
|
|
5534
5609
|
async function updatePushPreferences(config, preferences) {
|
|
5535
|
-
|
|
5536
|
-
|
|
5610
|
+
const endpoint = notificationsEndpoints.updatePreferences;
|
|
5611
|
+
await callApi(config, endpoint.path, {
|
|
5612
|
+
method: endpoint.method,
|
|
5537
5613
|
body: preferences
|
|
5538
5614
|
});
|
|
5539
5615
|
}
|
|
5540
5616
|
var segments = {
|
|
5541
5617
|
async create(config, input) {
|
|
5542
|
-
|
|
5618
|
+
const endpoint = notificationsEndpoints.createSegment;
|
|
5619
|
+
return callApi(config, endpoint.path, { method: endpoint.method, body: input });
|
|
5543
5620
|
},
|
|
5544
5621
|
async list(config) {
|
|
5545
|
-
|
|
5622
|
+
const endpoint = notificationsEndpoints.listSegments;
|
|
5623
|
+
return callApi(config, endpoint.path, { method: endpoint.method });
|
|
5546
5624
|
},
|
|
5547
5625
|
async get(config, id) {
|
|
5548
|
-
|
|
5626
|
+
const endpoint = notificationsEndpoints.getSegment;
|
|
5627
|
+
return callApi(config, interpolatePath2(endpoint.path, { id }), { method: endpoint.method });
|
|
5549
5628
|
},
|
|
5550
5629
|
async delete(config, id) {
|
|
5551
|
-
|
|
5630
|
+
const endpoint = notificationsEndpoints.deleteSegment;
|
|
5631
|
+
await callApi(config, interpolatePath2(endpoint.path, { id }), { method: endpoint.method });
|
|
5552
5632
|
}
|
|
5553
5633
|
};
|
|
5554
5634
|
var campaigns = {
|
|
5555
5635
|
async create(config, input) {
|
|
5556
|
-
|
|
5636
|
+
const endpoint = notificationsEndpoints.createCampaign;
|
|
5637
|
+
return callApi(config, endpoint.path, { method: endpoint.method, body: input });
|
|
5557
5638
|
},
|
|
5558
5639
|
async get(config, id) {
|
|
5559
|
-
|
|
5640
|
+
const endpoint = notificationsEndpoints.getCampaign;
|
|
5641
|
+
return callApi(config, interpolatePath2(endpoint.path, { id }), { method: endpoint.method });
|
|
5560
5642
|
},
|
|
5561
5643
|
async schedule(config, id, scheduledAt) {
|
|
5562
|
-
|
|
5563
|
-
|
|
5644
|
+
const endpoint = notificationsEndpoints.scheduleCampaign;
|
|
5645
|
+
return callApi(config, interpolatePath2(endpoint.path, { id }), {
|
|
5646
|
+
method: endpoint.method,
|
|
5564
5647
|
body: { scheduledAt }
|
|
5565
5648
|
});
|
|
5566
5649
|
},
|
|
5567
5650
|
async send(config, id) {
|
|
5568
|
-
|
|
5651
|
+
const endpoint = notificationsEndpoints.sendCampaign;
|
|
5652
|
+
return callApi(config, interpolatePath2(endpoint.path, { id }), { method: endpoint.method });
|
|
5569
5653
|
},
|
|
5570
5654
|
async cancel(config, id) {
|
|
5571
|
-
|
|
5655
|
+
const endpoint = notificationsEndpoints.cancelCampaign;
|
|
5656
|
+
return callApi(config, interpolatePath2(endpoint.path, { id }), { method: endpoint.method });
|
|
5572
5657
|
},
|
|
5573
5658
|
async stats(config, id) {
|
|
5574
|
-
|
|
5659
|
+
const endpoint = notificationsEndpoints.getCampaignStats;
|
|
5660
|
+
return callApi(config, interpolatePath2(endpoint.path, { id }), { method: endpoint.method });
|
|
5575
5661
|
}
|
|
5576
5662
|
};
|
|
5577
5663
|
|
|
@@ -6220,31 +6306,38 @@ async function getFlagPayload(config, flagKey, context) {
|
|
|
6220
6306
|
}
|
|
6221
6307
|
|
|
6222
6308
|
// src/webhooks.ts
|
|
6309
|
+
import { webhooksRuntimeEndpoints } from "@sylphx/contract";
|
|
6223
6310
|
async function getWebhookConfig(config) {
|
|
6224
|
-
|
|
6311
|
+
const endpoint = webhooksRuntimeEndpoints.getConfig;
|
|
6312
|
+
return callApi(config, endpoint.path, { method: endpoint.method });
|
|
6225
6313
|
}
|
|
6226
6314
|
async function updateWebhookConfig(config, data) {
|
|
6227
|
-
|
|
6315
|
+
const endpoint = webhooksRuntimeEndpoints.updateConfig;
|
|
6316
|
+
return callApi(config, endpoint.path, { method: endpoint.method, body: data });
|
|
6228
6317
|
}
|
|
6229
6318
|
async function getWebhookDeliveries(config, options) {
|
|
6230
|
-
|
|
6231
|
-
|
|
6319
|
+
const endpoint = webhooksRuntimeEndpoints.listDeliveries;
|
|
6320
|
+
return callApi(config, endpoint.path, {
|
|
6321
|
+
method: endpoint.method,
|
|
6232
6322
|
query: options
|
|
6233
6323
|
});
|
|
6234
6324
|
}
|
|
6235
6325
|
async function getWebhookDelivery(config, deliveryId) {
|
|
6236
|
-
|
|
6237
|
-
|
|
6326
|
+
const endpoint = webhooksRuntimeEndpoints.getDelivery;
|
|
6327
|
+
return callApi(config, interpolatePath2(endpoint.path, { deliveryId }), {
|
|
6328
|
+
method: endpoint.method
|
|
6238
6329
|
});
|
|
6239
6330
|
}
|
|
6240
6331
|
async function replayWebhookDelivery(config, deliveryId) {
|
|
6241
|
-
|
|
6242
|
-
|
|
6332
|
+
const endpoint = webhooksRuntimeEndpoints.replayDelivery;
|
|
6333
|
+
return callApi(config, interpolatePath2(endpoint.path, { deliveryId }), {
|
|
6334
|
+
method: endpoint.method
|
|
6243
6335
|
});
|
|
6244
6336
|
}
|
|
6245
6337
|
async function getWebhookStats(config, environmentId) {
|
|
6246
|
-
|
|
6247
|
-
|
|
6338
|
+
const endpoint = webhooksRuntimeEndpoints.getStats;
|
|
6339
|
+
return callApi(config, endpoint.path, {
|
|
6340
|
+
method: endpoint.method,
|
|
6248
6341
|
query: environmentId ? { environmentId } : void 0
|
|
6249
6342
|
});
|
|
6250
6343
|
}
|
|
@@ -6310,84 +6403,108 @@ async function getScheduledEmailStats(config) {
|
|
|
6310
6403
|
}
|
|
6311
6404
|
|
|
6312
6405
|
// src/consent.ts
|
|
6406
|
+
import { consentEndpoints } from "@sylphx/contract";
|
|
6407
|
+
function consentItemsFromRecord(consents) {
|
|
6408
|
+
return Object.entries(consents).map(([slug, granted]) => ({ slug, granted }));
|
|
6409
|
+
}
|
|
6313
6410
|
async function getConsentTypes(config) {
|
|
6314
|
-
|
|
6411
|
+
const endpoint = consentEndpoints.listTypes;
|
|
6412
|
+
return callApi(config, endpoint.path, { method: endpoint.method });
|
|
6315
6413
|
}
|
|
6316
6414
|
async function hasConsent(config, purposeSlug, input, defaults) {
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6415
|
+
const consents = await getUserConsents(config, input);
|
|
6416
|
+
const consent = consents.find((entry) => entry.slug === purposeSlug);
|
|
6417
|
+
if (consent) return consent.granted;
|
|
6418
|
+
if (defaults?.required) return true;
|
|
6419
|
+
return defaults?.defaultEnabled ?? false;
|
|
6321
6420
|
}
|
|
6322
6421
|
async function getUserConsents(config, input) {
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
|
|
6422
|
+
const endpoint = consentEndpoints.listUser;
|
|
6423
|
+
return callApi(config, endpoint.path, {
|
|
6424
|
+
method: endpoint.method,
|
|
6425
|
+
query: {
|
|
6426
|
+
userId: input.userId,
|
|
6427
|
+
anonymousId: input.anonymousId
|
|
6428
|
+
}
|
|
6326
6429
|
});
|
|
6327
6430
|
}
|
|
6328
6431
|
async function setConsents(config, input) {
|
|
6329
|
-
|
|
6432
|
+
const endpoint = consentEndpoints.set;
|
|
6433
|
+
await callApi(config, endpoint.path, {
|
|
6434
|
+
method: endpoint.method,
|
|
6435
|
+
body: {
|
|
6436
|
+
userId: input.userId,
|
|
6437
|
+
anonymousId: input.anonymousId,
|
|
6438
|
+
consents: consentItemsFromRecord(input.consents),
|
|
6439
|
+
source: input.source,
|
|
6440
|
+
userAgent: input.userAgent
|
|
6441
|
+
}
|
|
6442
|
+
});
|
|
6330
6443
|
}
|
|
6331
6444
|
async function acceptAllConsents(config, input) {
|
|
6332
|
-
|
|
6333
|
-
|
|
6445
|
+
const endpoint = consentEndpoints.acceptAll;
|
|
6446
|
+
await callApi(config, endpoint.path, {
|
|
6447
|
+
method: endpoint.method,
|
|
6334
6448
|
body: input
|
|
6335
6449
|
});
|
|
6336
6450
|
}
|
|
6337
6451
|
async function declineOptionalConsents(config, input) {
|
|
6338
|
-
|
|
6339
|
-
|
|
6452
|
+
const endpoint = consentEndpoints.declineOptional;
|
|
6453
|
+
await callApi(config, endpoint.path, {
|
|
6454
|
+
method: endpoint.method,
|
|
6340
6455
|
body: input
|
|
6341
6456
|
});
|
|
6342
6457
|
}
|
|
6343
6458
|
async function linkAnonymousConsents(config, input) {
|
|
6344
|
-
|
|
6345
|
-
|
|
6459
|
+
const endpoint = consentEndpoints.linkAnonymous;
|
|
6460
|
+
await callApi(config, endpoint.path, {
|
|
6461
|
+
method: endpoint.method,
|
|
6346
6462
|
body: input
|
|
6347
6463
|
});
|
|
6348
6464
|
}
|
|
6349
6465
|
async function getConsentHistory(config, input) {
|
|
6350
|
-
|
|
6351
|
-
|
|
6466
|
+
const endpoint = consentEndpoints.history;
|
|
6467
|
+
return callApi(config, endpoint.path, {
|
|
6468
|
+
method: endpoint.method,
|
|
6352
6469
|
query: {
|
|
6353
6470
|
userId: input.userId,
|
|
6354
6471
|
anonymousId: input.anonymousId,
|
|
6355
|
-
limit: input.limit
|
|
6472
|
+
limit: input.limit,
|
|
6356
6473
|
cursor: input.cursor
|
|
6357
6474
|
}
|
|
6358
6475
|
});
|
|
6359
6476
|
}
|
|
6360
6477
|
|
|
6361
6478
|
// src/referrals.ts
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
});
|
|
6479
|
+
import { referralsEndpoints } from "@sylphx/contract";
|
|
6480
|
+
async function getMyReferralCode(config, _userId) {
|
|
6481
|
+
const endpoint = referralsEndpoints.getCode;
|
|
6482
|
+
return callApi(config, endpoint.path, { method: endpoint.method });
|
|
6367
6483
|
}
|
|
6368
|
-
async function getReferralStats(config,
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
query: { userId }
|
|
6372
|
-
});
|
|
6484
|
+
async function getReferralStats(config, _userId) {
|
|
6485
|
+
const endpoint = referralsEndpoints.stats;
|
|
6486
|
+
return callApi(config, endpoint.path, { method: endpoint.method });
|
|
6373
6487
|
}
|
|
6374
6488
|
async function redeemReferralCode(config, input, defaults) {
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6489
|
+
const endpoint = referralsEndpoints.redeem;
|
|
6490
|
+
return callApi(config, endpoint.path, {
|
|
6491
|
+
method: endpoint.method,
|
|
6492
|
+
body: { code: input.code, defaults }
|
|
6378
6493
|
});
|
|
6379
6494
|
}
|
|
6380
|
-
async function getReferralLeaderboard(config,
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6495
|
+
async function getReferralLeaderboard(config, _userId, options) {
|
|
6496
|
+
const endpoint = referralsEndpoints.leaderboard;
|
|
6497
|
+
return callApi(config, endpoint.path, {
|
|
6498
|
+
method: endpoint.method,
|
|
6499
|
+
query: {
|
|
6500
|
+
limit: options?.limit,
|
|
6501
|
+
period: options?.period
|
|
6502
|
+
}
|
|
6384
6503
|
});
|
|
6385
6504
|
}
|
|
6386
|
-
async function regenerateReferralCode(config,
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
body: { userId }
|
|
6390
|
-
});
|
|
6505
|
+
async function regenerateReferralCode(config, _userId) {
|
|
6506
|
+
const endpoint = referralsEndpoints.regenerateCode;
|
|
6507
|
+
return callApi(config, endpoint.path, { method: endpoint.method });
|
|
6391
6508
|
}
|
|
6392
6509
|
|
|
6393
6510
|
// src/lib/engagement/types.ts
|
|
@@ -6828,7 +6945,7 @@ async function getDatabaseStatus(config) {
|
|
|
6828
6945
|
|
|
6829
6946
|
// src/kv.ts
|
|
6830
6947
|
import { kvEndpoints } from "@sylphx/contract";
|
|
6831
|
-
function
|
|
6948
|
+
function interpolatePath3(template, params) {
|
|
6832
6949
|
let path = template;
|
|
6833
6950
|
for (const [key, value] of Object.entries(params)) {
|
|
6834
6951
|
path = path.replace(`:${key}`, encodeURIComponent(value));
|
|
@@ -6873,20 +6990,20 @@ async function kvGet(config, key) {
|
|
|
6873
6990
|
const endpoint = kvEndpoints.get;
|
|
6874
6991
|
const result = await callApi(
|
|
6875
6992
|
config,
|
|
6876
|
-
|
|
6993
|
+
interpolatePath3(endpoint.path, { key }),
|
|
6877
6994
|
{ method: endpoint.method }
|
|
6878
6995
|
);
|
|
6879
6996
|
return result.value;
|
|
6880
6997
|
}
|
|
6881
6998
|
async function kvDelete(config, key) {
|
|
6882
6999
|
const endpoint = kvEndpoints.delete;
|
|
6883
|
-
return callApi(config,
|
|
7000
|
+
return callApi(config, interpolatePath3(endpoint.path, { key }), {
|
|
6884
7001
|
method: endpoint.method
|
|
6885
7002
|
});
|
|
6886
7003
|
}
|
|
6887
7004
|
async function kvExists(config, key) {
|
|
6888
7005
|
const endpoint = kvEndpoints.exists;
|
|
6889
|
-
return callApi(config,
|
|
7006
|
+
return callApi(config, interpolatePath3(endpoint.path, { key }), {
|
|
6890
7007
|
method: endpoint.method
|
|
6891
7008
|
});
|
|
6892
7009
|
}
|
|
@@ -7592,7 +7709,8 @@ var SandboxClient = class _SandboxClient {
|
|
|
7592
7709
|
env: options?.env,
|
|
7593
7710
|
storage: options?.storageGi !== void 0 ? { enabled: true, sizeGi: options.storageGi } : void 0,
|
|
7594
7711
|
volumeMounts: options?.volumeMounts,
|
|
7595
|
-
workspaceMounts: options?.workspaceMounts
|
|
7712
|
+
workspaceMounts: options?.workspaceMounts,
|
|
7713
|
+
egress: options?.egress
|
|
7596
7714
|
},
|
|
7597
7715
|
timeout: options?.createTimeoutMs ?? SANDBOX_CREATE_TIMEOUT_MS
|
|
7598
7716
|
});
|