@sylphx/sdk 0.3.7 → 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.mjs CHANGED
@@ -103,6 +103,13 @@ var SylphxError = class _SylphxError extends Error {
103
103
  static isRateLimited(err) {
104
104
  return err instanceof _SylphxError && err.code === "TOO_MANY_REQUESTS";
105
105
  }
106
+ /**
107
+ * Check if error is an account lockout error (too many failed login attempts).
108
+ * When true, `error.data?.lockoutUntil` contains the ISO 8601 timestamp when the lockout expires.
109
+ */
110
+ static isAccountLocked(err) {
111
+ return err instanceof _SylphxError && err.code === "TOO_MANY_REQUESTS" && err.data?.code === "ACCOUNT_LOCKED";
112
+ }
106
113
  /**
107
114
  * Check if error is a quota exceeded error (plan limit reached)
108
115
  */
@@ -2685,6 +2692,86 @@ function canDeleteOrganization(membership) {
2685
2692
  return hasRole(membership, "super_admin");
2686
2693
  }
2687
2694
 
2695
+ // src/permissions.ts
2696
+ async function listPermissions(config) {
2697
+ return callApi(config, "/permissions");
2698
+ }
2699
+ async function createPermission(config, input) {
2700
+ return callApi(config, "/permissions", {
2701
+ method: "POST",
2702
+ body: input
2703
+ });
2704
+ }
2705
+ async function deletePermission(config, permissionKey) {
2706
+ return callApi(config, `/permissions/${permissionKey}`, {
2707
+ method: "DELETE"
2708
+ });
2709
+ }
2710
+ async function getMemberPermissions(config, orgIdOrSlug, memberId) {
2711
+ return callApi(
2712
+ config,
2713
+ `/orgs/${orgIdOrSlug}/members/${memberId}/permissions`
2714
+ );
2715
+ }
2716
+ function hasPermission(permissions, required) {
2717
+ return permissions.includes(required);
2718
+ }
2719
+ function hasAnyPermission(permissions, required) {
2720
+ return required.some((perm) => permissions.includes(perm));
2721
+ }
2722
+ function hasAllPermissions(permissions, required) {
2723
+ return required.every((perm) => permissions.includes(perm));
2724
+ }
2725
+
2726
+ // src/roles.ts
2727
+ async function listRoles(config) {
2728
+ return callApi(config, "/roles");
2729
+ }
2730
+ async function getRole(config, roleKey) {
2731
+ return callApi(config, `/roles/${roleKey}`);
2732
+ }
2733
+ async function createRole(config, input) {
2734
+ const body = {
2735
+ key: input.key,
2736
+ name: input.name
2737
+ };
2738
+ if (input.description !== void 0) body.description = input.description;
2739
+ if (input.permissions !== void 0) body.permissionKeys = input.permissions;
2740
+ if (input.isDefault !== void 0) body.isDefault = input.isDefault;
2741
+ if (input.sortOrder !== void 0) body.sortOrder = input.sortOrder;
2742
+ return callApi(config, "/roles", {
2743
+ method: "POST",
2744
+ body
2745
+ });
2746
+ }
2747
+ async function updateRole(config, roleKey, input) {
2748
+ const body = {};
2749
+ if (input.name !== void 0) body.name = input.name;
2750
+ if (input.description !== void 0) body.description = input.description;
2751
+ if (input.permissions !== void 0) body.permissionKeys = input.permissions;
2752
+ if (input.isDefault !== void 0) body.isDefault = input.isDefault;
2753
+ if (input.sortOrder !== void 0) body.sortOrder = input.sortOrder;
2754
+ return callApi(config, `/roles/${roleKey}`, {
2755
+ method: "PUT",
2756
+ body
2757
+ });
2758
+ }
2759
+ async function deleteRole(config, roleKey) {
2760
+ return callApi(config, `/roles/${roleKey}`, {
2761
+ method: "DELETE"
2762
+ });
2763
+ }
2764
+ async function assignMemberRole(config, orgIdOrSlug, memberId, roleKey) {
2765
+ return callApi(
2766
+ config,
2767
+ `/orgs/${orgIdOrSlug}/members/${memberId}/assign-role`,
2768
+ {
2769
+ method: "PUT",
2770
+ body: { roleKey }
2771
+ }
2772
+ );
2773
+ }
2774
+
2688
2775
  // src/secrets.ts
2689
2776
  async function getSecret(config, input) {
2690
2777
  return callApi(config, "/secrets/get", {
@@ -3532,6 +3619,7 @@ export {
3532
3619
  WorkersClient,
3533
3620
  acceptAllConsents,
3534
3621
  acceptOrganizationInvitation,
3622
+ assignMemberRole,
3535
3623
  batchIndex,
3536
3624
  canDeleteOrganization,
3537
3625
  canManageMembers,
@@ -3550,8 +3638,10 @@ export {
3550
3638
  createCron,
3551
3639
  createDynamicRestClient,
3552
3640
  createOrganization,
3641
+ createPermission,
3553
3642
  createPortalSession,
3554
3643
  createRestClient,
3644
+ createRole,
3555
3645
  createServiceWorkerScript,
3556
3646
  createStepContext,
3557
3647
  createTasksHandler,
@@ -3566,6 +3656,8 @@ export {
3566
3656
  deleteEnvVar,
3567
3657
  deleteFile,
3568
3658
  deleteOrganization,
3659
+ deletePermission,
3660
+ deleteRole,
3569
3661
  deleteUser,
3570
3662
  disableDebug,
3571
3663
  embed,
@@ -3599,6 +3691,7 @@ export {
3599
3691
  getFlagPayload,
3600
3692
  getFlags,
3601
3693
  getLeaderboard,
3694
+ getMemberPermissions,
3602
3695
  getMyReferralCode,
3603
3696
  getOrganization,
3604
3697
  getOrganizationInvitations,
@@ -3610,6 +3703,7 @@ export {
3610
3703
  getReferralLeaderboard,
3611
3704
  getReferralStats,
3612
3705
  getRestErrorMessage,
3706
+ getRole,
3613
3707
  getScheduledEmail,
3614
3708
  getScheduledEmailStats,
3615
3709
  getSearchStats,
@@ -3629,8 +3723,11 @@ export {
3629
3723
  getWebhookDeliveries,
3630
3724
  getWebhookDelivery,
3631
3725
  getWebhookStats,
3726
+ hasAllPermissions,
3727
+ hasAnyPermission,
3632
3728
  hasConsent,
3633
3729
  hasError,
3730
+ hasPermission,
3634
3731
  hasRole,
3635
3732
  hasSecret,
3636
3733
  identify,
@@ -3667,6 +3764,8 @@ export {
3667
3764
  leaveOrganization,
3668
3765
  linkAnonymousConsents,
3669
3766
  listEnvVars,
3767
+ listPermissions,
3768
+ listRoles,
3670
3769
  listScheduledEmails,
3671
3770
  listSecretKeys,
3672
3771
  listTasks,
@@ -3719,6 +3818,7 @@ export {
3719
3818
  updateOrganization,
3720
3819
  updateOrganizationMemberRole,
3721
3820
  updatePushPreferences,
3821
+ updateRole,
3722
3822
  updateUser,
3723
3823
  updateUserMetadata,
3724
3824
  updateWebhookConfig,