@sylphx/sdk 0.3.6 → 0.4.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/index.d.cts +376 -1
- package/dist/index.d.ts +376 -1
- package/dist/index.js +127 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +113 -3
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs/index.js +7 -2
- package/dist/nextjs/index.js.map +1 -1
- package/dist/nextjs/index.mjs +7 -2
- package/dist/nextjs/index.mjs.map +1 -1
- package/dist/react/index.d.cts +330 -1
- package/dist/react/index.d.ts +330 -1
- package/dist/react/index.js +710 -543
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +384 -221
- package/dist/react/index.mjs.map +1 -1
- package/dist/server/index.js +30 -11
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +30 -11
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -49,6 +49,7 @@ __export(index_exports, {
|
|
|
49
49
|
WorkersClient: () => WorkersClient,
|
|
50
50
|
acceptAllConsents: () => acceptAllConsents,
|
|
51
51
|
acceptOrganizationInvitation: () => acceptOrganizationInvitation,
|
|
52
|
+
assignMemberRole: () => assignMemberRole,
|
|
52
53
|
batchIndex: () => batchIndex,
|
|
53
54
|
canDeleteOrganization: () => canDeleteOrganization,
|
|
54
55
|
canManageMembers: () => canManageMembers,
|
|
@@ -67,8 +68,10 @@ __export(index_exports, {
|
|
|
67
68
|
createCron: () => createCron,
|
|
68
69
|
createDynamicRestClient: () => createDynamicRestClient,
|
|
69
70
|
createOrganization: () => createOrganization,
|
|
71
|
+
createPermission: () => createPermission,
|
|
70
72
|
createPortalSession: () => createPortalSession,
|
|
71
73
|
createRestClient: () => createRestClient,
|
|
74
|
+
createRole: () => createRole,
|
|
72
75
|
createServiceWorkerScript: () => createServiceWorkerScript,
|
|
73
76
|
createStepContext: () => createStepContext,
|
|
74
77
|
createTasksHandler: () => createTasksHandler,
|
|
@@ -83,6 +86,8 @@ __export(index_exports, {
|
|
|
83
86
|
deleteEnvVar: () => deleteEnvVar,
|
|
84
87
|
deleteFile: () => deleteFile,
|
|
85
88
|
deleteOrganization: () => deleteOrganization,
|
|
89
|
+
deletePermission: () => deletePermission,
|
|
90
|
+
deleteRole: () => deleteRole,
|
|
86
91
|
deleteUser: () => deleteUser,
|
|
87
92
|
disableDebug: () => disableDebug,
|
|
88
93
|
embed: () => embed,
|
|
@@ -116,6 +121,7 @@ __export(index_exports, {
|
|
|
116
121
|
getFlagPayload: () => getFlagPayload,
|
|
117
122
|
getFlags: () => getFlags,
|
|
118
123
|
getLeaderboard: () => getLeaderboard,
|
|
124
|
+
getMemberPermissions: () => getMemberPermissions,
|
|
119
125
|
getMyReferralCode: () => getMyReferralCode,
|
|
120
126
|
getOrganization: () => getOrganization,
|
|
121
127
|
getOrganizationInvitations: () => getOrganizationInvitations,
|
|
@@ -127,6 +133,7 @@ __export(index_exports, {
|
|
|
127
133
|
getReferralLeaderboard: () => getReferralLeaderboard,
|
|
128
134
|
getReferralStats: () => getReferralStats,
|
|
129
135
|
getRestErrorMessage: () => getRestErrorMessage,
|
|
136
|
+
getRole: () => getRole,
|
|
130
137
|
getScheduledEmail: () => getScheduledEmail,
|
|
131
138
|
getScheduledEmailStats: () => getScheduledEmailStats,
|
|
132
139
|
getSearchStats: () => getSearchStats,
|
|
@@ -146,8 +153,11 @@ __export(index_exports, {
|
|
|
146
153
|
getWebhookDeliveries: () => getWebhookDeliveries,
|
|
147
154
|
getWebhookDelivery: () => getWebhookDelivery,
|
|
148
155
|
getWebhookStats: () => getWebhookStats,
|
|
156
|
+
hasAllPermissions: () => hasAllPermissions,
|
|
157
|
+
hasAnyPermission: () => hasAnyPermission,
|
|
149
158
|
hasConsent: () => hasConsent,
|
|
150
159
|
hasError: () => hasError,
|
|
160
|
+
hasPermission: () => hasPermission,
|
|
151
161
|
hasRole: () => hasRole,
|
|
152
162
|
hasSecret: () => hasSecret,
|
|
153
163
|
identify: () => identify,
|
|
@@ -184,6 +194,8 @@ __export(index_exports, {
|
|
|
184
194
|
leaveOrganization: () => leaveOrganization,
|
|
185
195
|
linkAnonymousConsents: () => linkAnonymousConsents,
|
|
186
196
|
listEnvVars: () => listEnvVars,
|
|
197
|
+
listPermissions: () => listPermissions,
|
|
198
|
+
listRoles: () => listRoles,
|
|
187
199
|
listScheduledEmails: () => listScheduledEmails,
|
|
188
200
|
listSecretKeys: () => listSecretKeys,
|
|
189
201
|
listTasks: () => listTasks,
|
|
@@ -225,6 +237,7 @@ __export(index_exports, {
|
|
|
225
237
|
streamToString: () => streamToString,
|
|
226
238
|
submitScore: () => submitScore,
|
|
227
239
|
suspendUser: () => suspendUser,
|
|
240
|
+
switchOrg: () => switchOrg,
|
|
228
241
|
toSylphxError: () => toSylphxError,
|
|
229
242
|
track: () => track,
|
|
230
243
|
trackBatch: () => trackBatch,
|
|
@@ -235,6 +248,7 @@ __export(index_exports, {
|
|
|
235
248
|
updateOrganization: () => updateOrganization,
|
|
236
249
|
updateOrganizationMemberRole: () => updateOrganizationMemberRole,
|
|
237
250
|
updatePushPreferences: () => updatePushPreferences,
|
|
251
|
+
updateRole: () => updateRole,
|
|
238
252
|
updateUser: () => updateUser,
|
|
239
253
|
updateUserMetadata: () => updateUserMetadata,
|
|
240
254
|
updateWebhookConfig: () => updateWebhookConfig,
|
|
@@ -353,6 +367,13 @@ var SylphxError = class _SylphxError extends Error {
|
|
|
353
367
|
static isRateLimited(err) {
|
|
354
368
|
return err instanceof _SylphxError && err.code === "TOO_MANY_REQUESTS";
|
|
355
369
|
}
|
|
370
|
+
/**
|
|
371
|
+
* Check if error is an account lockout error (too many failed login attempts).
|
|
372
|
+
* When true, `error.data?.lockoutUntil` contains the ISO 8601 timestamp when the lockout expires.
|
|
373
|
+
*/
|
|
374
|
+
static isAccountLocked(err) {
|
|
375
|
+
return err instanceof _SylphxError && err.code === "TOO_MANY_REQUESTS" && err.data?.code === "ACCOUNT_LOCKED";
|
|
376
|
+
}
|
|
356
377
|
/**
|
|
357
378
|
* Check if error is a quota exceeded error (plan limit reached)
|
|
358
379
|
*/
|
|
@@ -1564,11 +1585,14 @@ async function verifyTwoFactor(config, userId, code) {
|
|
|
1564
1585
|
async function introspectToken(config, token, tokenTypeHint) {
|
|
1565
1586
|
const response = await fetch(buildApiUrl(config, "/auth/introspect"), {
|
|
1566
1587
|
method: "POST",
|
|
1567
|
-
headers: {
|
|
1588
|
+
headers: {
|
|
1589
|
+
"Content-Type": "application/json",
|
|
1590
|
+
// RFC 7662 §2: server-to-server call — authenticate with secret key
|
|
1591
|
+
"x-app-secret": config.secretKey ?? ""
|
|
1592
|
+
},
|
|
1568
1593
|
body: JSON.stringify({
|
|
1569
1594
|
token,
|
|
1570
|
-
token_type_hint: tokenTypeHint
|
|
1571
|
-
client_secret: config.secretKey
|
|
1595
|
+
token_type_hint: tokenTypeHint
|
|
1572
1596
|
})
|
|
1573
1597
|
});
|
|
1574
1598
|
if (!response.ok) {
|
|
@@ -1603,6 +1627,12 @@ async function inviteUser(config, input) {
|
|
|
1603
1627
|
body: input
|
|
1604
1628
|
});
|
|
1605
1629
|
}
|
|
1630
|
+
async function switchOrg(config, orgId) {
|
|
1631
|
+
return callApi(config, "/auth/switch-org", {
|
|
1632
|
+
method: "POST",
|
|
1633
|
+
body: JSON.stringify({ orgId })
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1606
1636
|
|
|
1607
1637
|
// src/admin.ts
|
|
1608
1638
|
async function listUsers(config, opts) {
|
|
@@ -2926,6 +2956,86 @@ function canDeleteOrganization(membership) {
|
|
|
2926
2956
|
return hasRole(membership, "super_admin");
|
|
2927
2957
|
}
|
|
2928
2958
|
|
|
2959
|
+
// src/permissions.ts
|
|
2960
|
+
async function listPermissions(config) {
|
|
2961
|
+
return callApi(config, "/permissions");
|
|
2962
|
+
}
|
|
2963
|
+
async function createPermission(config, input) {
|
|
2964
|
+
return callApi(config, "/permissions", {
|
|
2965
|
+
method: "POST",
|
|
2966
|
+
body: input
|
|
2967
|
+
});
|
|
2968
|
+
}
|
|
2969
|
+
async function deletePermission(config, permissionKey) {
|
|
2970
|
+
return callApi(config, `/permissions/${permissionKey}`, {
|
|
2971
|
+
method: "DELETE"
|
|
2972
|
+
});
|
|
2973
|
+
}
|
|
2974
|
+
async function getMemberPermissions(config, orgIdOrSlug, memberId) {
|
|
2975
|
+
return callApi(
|
|
2976
|
+
config,
|
|
2977
|
+
`/orgs/${orgIdOrSlug}/members/${memberId}/permissions`
|
|
2978
|
+
);
|
|
2979
|
+
}
|
|
2980
|
+
function hasPermission(permissions, required) {
|
|
2981
|
+
return permissions.includes(required);
|
|
2982
|
+
}
|
|
2983
|
+
function hasAnyPermission(permissions, required) {
|
|
2984
|
+
return required.some((perm) => permissions.includes(perm));
|
|
2985
|
+
}
|
|
2986
|
+
function hasAllPermissions(permissions, required) {
|
|
2987
|
+
return required.every((perm) => permissions.includes(perm));
|
|
2988
|
+
}
|
|
2989
|
+
|
|
2990
|
+
// src/roles.ts
|
|
2991
|
+
async function listRoles(config) {
|
|
2992
|
+
return callApi(config, "/roles");
|
|
2993
|
+
}
|
|
2994
|
+
async function getRole(config, roleKey) {
|
|
2995
|
+
return callApi(config, `/roles/${roleKey}`);
|
|
2996
|
+
}
|
|
2997
|
+
async function createRole(config, input) {
|
|
2998
|
+
const body = {
|
|
2999
|
+
key: input.key,
|
|
3000
|
+
name: input.name
|
|
3001
|
+
};
|
|
3002
|
+
if (input.description !== void 0) body.description = input.description;
|
|
3003
|
+
if (input.permissions !== void 0) body.permissionKeys = input.permissions;
|
|
3004
|
+
if (input.isDefault !== void 0) body.isDefault = input.isDefault;
|
|
3005
|
+
if (input.sortOrder !== void 0) body.sortOrder = input.sortOrder;
|
|
3006
|
+
return callApi(config, "/roles", {
|
|
3007
|
+
method: "POST",
|
|
3008
|
+
body
|
|
3009
|
+
});
|
|
3010
|
+
}
|
|
3011
|
+
async function updateRole(config, roleKey, input) {
|
|
3012
|
+
const body = {};
|
|
3013
|
+
if (input.name !== void 0) body.name = input.name;
|
|
3014
|
+
if (input.description !== void 0) body.description = input.description;
|
|
3015
|
+
if (input.permissions !== void 0) body.permissionKeys = input.permissions;
|
|
3016
|
+
if (input.isDefault !== void 0) body.isDefault = input.isDefault;
|
|
3017
|
+
if (input.sortOrder !== void 0) body.sortOrder = input.sortOrder;
|
|
3018
|
+
return callApi(config, `/roles/${roleKey}`, {
|
|
3019
|
+
method: "PUT",
|
|
3020
|
+
body
|
|
3021
|
+
});
|
|
3022
|
+
}
|
|
3023
|
+
async function deleteRole(config, roleKey) {
|
|
3024
|
+
return callApi(config, `/roles/${roleKey}`, {
|
|
3025
|
+
method: "DELETE"
|
|
3026
|
+
});
|
|
3027
|
+
}
|
|
3028
|
+
async function assignMemberRole(config, orgIdOrSlug, memberId, roleKey) {
|
|
3029
|
+
return callApi(
|
|
3030
|
+
config,
|
|
3031
|
+
`/orgs/${orgIdOrSlug}/members/${memberId}/assign-role`,
|
|
3032
|
+
{
|
|
3033
|
+
method: "PUT",
|
|
3034
|
+
body: { roleKey }
|
|
3035
|
+
}
|
|
3036
|
+
);
|
|
3037
|
+
}
|
|
3038
|
+
|
|
2929
3039
|
// src/secrets.ts
|
|
2930
3040
|
async function getSecret(config, input) {
|
|
2931
3041
|
return callApi(config, "/secrets/get", {
|
|
@@ -3774,6 +3884,7 @@ function sleep2(ms) {
|
|
|
3774
3884
|
WorkersClient,
|
|
3775
3885
|
acceptAllConsents,
|
|
3776
3886
|
acceptOrganizationInvitation,
|
|
3887
|
+
assignMemberRole,
|
|
3777
3888
|
batchIndex,
|
|
3778
3889
|
canDeleteOrganization,
|
|
3779
3890
|
canManageMembers,
|
|
@@ -3792,8 +3903,10 @@ function sleep2(ms) {
|
|
|
3792
3903
|
createCron,
|
|
3793
3904
|
createDynamicRestClient,
|
|
3794
3905
|
createOrganization,
|
|
3906
|
+
createPermission,
|
|
3795
3907
|
createPortalSession,
|
|
3796
3908
|
createRestClient,
|
|
3909
|
+
createRole,
|
|
3797
3910
|
createServiceWorkerScript,
|
|
3798
3911
|
createStepContext,
|
|
3799
3912
|
createTasksHandler,
|
|
@@ -3808,6 +3921,8 @@ function sleep2(ms) {
|
|
|
3808
3921
|
deleteEnvVar,
|
|
3809
3922
|
deleteFile,
|
|
3810
3923
|
deleteOrganization,
|
|
3924
|
+
deletePermission,
|
|
3925
|
+
deleteRole,
|
|
3811
3926
|
deleteUser,
|
|
3812
3927
|
disableDebug,
|
|
3813
3928
|
embed,
|
|
@@ -3841,6 +3956,7 @@ function sleep2(ms) {
|
|
|
3841
3956
|
getFlagPayload,
|
|
3842
3957
|
getFlags,
|
|
3843
3958
|
getLeaderboard,
|
|
3959
|
+
getMemberPermissions,
|
|
3844
3960
|
getMyReferralCode,
|
|
3845
3961
|
getOrganization,
|
|
3846
3962
|
getOrganizationInvitations,
|
|
@@ -3852,6 +3968,7 @@ function sleep2(ms) {
|
|
|
3852
3968
|
getReferralLeaderboard,
|
|
3853
3969
|
getReferralStats,
|
|
3854
3970
|
getRestErrorMessage,
|
|
3971
|
+
getRole,
|
|
3855
3972
|
getScheduledEmail,
|
|
3856
3973
|
getScheduledEmailStats,
|
|
3857
3974
|
getSearchStats,
|
|
@@ -3871,8 +3988,11 @@ function sleep2(ms) {
|
|
|
3871
3988
|
getWebhookDeliveries,
|
|
3872
3989
|
getWebhookDelivery,
|
|
3873
3990
|
getWebhookStats,
|
|
3991
|
+
hasAllPermissions,
|
|
3992
|
+
hasAnyPermission,
|
|
3874
3993
|
hasConsent,
|
|
3875
3994
|
hasError,
|
|
3995
|
+
hasPermission,
|
|
3876
3996
|
hasRole,
|
|
3877
3997
|
hasSecret,
|
|
3878
3998
|
identify,
|
|
@@ -3909,6 +4029,8 @@ function sleep2(ms) {
|
|
|
3909
4029
|
leaveOrganization,
|
|
3910
4030
|
linkAnonymousConsents,
|
|
3911
4031
|
listEnvVars,
|
|
4032
|
+
listPermissions,
|
|
4033
|
+
listRoles,
|
|
3912
4034
|
listScheduledEmails,
|
|
3913
4035
|
listSecretKeys,
|
|
3914
4036
|
listTasks,
|
|
@@ -3950,6 +4072,7 @@ function sleep2(ms) {
|
|
|
3950
4072
|
streamToString,
|
|
3951
4073
|
submitScore,
|
|
3952
4074
|
suspendUser,
|
|
4075
|
+
switchOrg,
|
|
3953
4076
|
toSylphxError,
|
|
3954
4077
|
track,
|
|
3955
4078
|
trackBatch,
|
|
@@ -3960,6 +4083,7 @@ function sleep2(ms) {
|
|
|
3960
4083
|
updateOrganization,
|
|
3961
4084
|
updateOrganizationMemberRole,
|
|
3962
4085
|
updatePushPreferences,
|
|
4086
|
+
updateRole,
|
|
3963
4087
|
updateUser,
|
|
3964
4088
|
updateUserMetadata,
|
|
3965
4089
|
updateWebhookConfig,
|