memorysync-sdk 1.4.0 → 1.6.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
@@ -532,7 +532,7 @@ var IntegrationsNamespace = class extends Namespace {
532
532
  };
533
533
 
534
534
  // src/control-plane.ts
535
- var SDK_VERSION = "1.4.0";
535
+ var SDK_VERSION = "1.6.0";
536
536
  function safeJson(text) {
537
537
  try {
538
538
  return JSON.parse(text);
@@ -609,17 +609,51 @@ function boundedInteger(value, name, minimum, maximum) {
609
609
  throw new ValidationError(`${name} must be an integer between ${minimum} and ${maximum}`);
610
610
  }
611
611
  }
612
- function nonNegativeInteger(value, name) {
613
- if (!Number.isInteger(value) || value < 0) {
614
- throw new ValidationError(`${name} must be a non-negative integer`);
615
- }
616
- }
617
612
  function nonEmptyStrings(values, name) {
618
613
  if (!Array.isArray(values) || values.length === 0 || values.some((value) => typeof value !== "string" || !value.trim())) {
619
614
  throw new ValidationError(`${name} must contain at least one non-empty string`);
620
615
  }
621
616
  }
617
+ function projectName(value) {
618
+ nonEmpty(value, "name");
619
+ if (value.length > 200) throw new ValidationError("name may contain at most 200 characters");
620
+ }
621
+ function pathId(value, name, minimum = 1, maximum) {
622
+ nonEmpty(value, name);
623
+ const trimmed = value.trim();
624
+ if (trimmed.length < minimum || maximum !== void 0 && trimmed.length > maximum) {
625
+ const range = maximum === void 0 ? `at least ${minimum}` : `between ${minimum} and ${maximum}`;
626
+ throw new ValidationError(`${name} must contain ${range} characters`);
627
+ }
628
+ return encodeURIComponent(trimmed);
629
+ }
630
+ function validateWebhookRetryConfig(config) {
631
+ if (config.maxRetries !== void 0) boundedInteger(config.maxRetries, "maxRetries", 1, 10);
632
+ if (config.initialDelaySeconds !== void 0) boundedInteger(config.initialDelaySeconds, "initialDelaySeconds", 1, 60);
633
+ if (config.maxDelaySeconds !== void 0) boundedInteger(config.maxDelaySeconds, "maxDelaySeconds", 60, 86400);
634
+ if (config.backoffMultiplier !== void 0 && (!Number.isFinite(config.backoffMultiplier) || config.backoffMultiplier < 1 || config.backoffMultiplier > 5)) {
635
+ throw new ValidationError("backoffMultiplier must be between 1 and 5");
636
+ }
637
+ if (config.retryStatusCodes !== void 0 && (!Array.isArray(config.retryStatusCodes) || config.retryStatusCodes.length === 0 || config.retryStatusCodes.some((value) => typeof value !== "string" || value.trim().length === 0))) {
638
+ throw new ValidationError("retryStatusCodes must contain at least one non-empty string");
639
+ }
640
+ }
641
+ function validateWebhookSignatureConfig(config) {
642
+ if (config.algorithm !== void 0 && config.algorithm !== "hmac-sha256" && config.algorithm !== "hmac-sha512") {
643
+ throw new ValidationError("algorithm must be 'hmac-sha256' or 'hmac-sha512'");
644
+ }
645
+ for (const [name, value] of [["headerName", config.headerName], ["timestampHeader", config.timestampHeader]]) {
646
+ if (value !== void 0 && value.trim().length === 0) {
647
+ throw new ValidationError(`${name} must be a non-empty string`);
648
+ }
649
+ if (value !== void 0 && value.length > 64) {
650
+ throw new ValidationError(`${name} may contain at most 64 characters`);
651
+ }
652
+ }
653
+ if (config.toleranceSeconds !== void 0) boundedInteger(config.toleranceSeconds, "toleranceSeconds", 60, 3600);
654
+ }
622
655
  function webhookRetryConfig(config) {
656
+ validateWebhookRetryConfig(config);
623
657
  const wire = {};
624
658
  if (config.enabled !== void 0) wire.enabled = config.enabled;
625
659
  if (config.maxRetries !== void 0) wire.max_retries = config.maxRetries;
@@ -630,6 +664,7 @@ function webhookRetryConfig(config) {
630
664
  return wire;
631
665
  }
632
666
  function webhookSignatureConfig(config) {
667
+ validateWebhookSignatureConfig(config);
633
668
  const wire = {};
634
669
  if (config.algorithm !== void 0) wire.algorithm = config.algorithm;
635
670
  if (config.headerName !== void 0) wire.header_name = config.headerName;
@@ -637,6 +672,19 @@ function webhookSignatureConfig(config) {
637
672
  if (config.toleranceSeconds !== void 0) wire.tolerance_seconds = config.toleranceSeconds;
638
673
  return wire;
639
674
  }
675
+ function exportFilters(filters) {
676
+ const wire = {};
677
+ if (filters.q !== void 0) wire.q = filters.q;
678
+ if (filters.userId !== void 0) wire.user_id = filters.userId;
679
+ if (filters.isSummary !== void 0) wire.is_summary = filters.isSummary;
680
+ if (filters.tier !== void 0) wire.tier = filters.tier;
681
+ if (filters.source !== void 0) wire.source = filters.source;
682
+ if (filters.timeRange !== void 0) wire.time_range = filters.timeRange;
683
+ if (filters.dateFrom !== void 0) wire.date_from = filters.dateFrom;
684
+ if (filters.dateTo !== void 0) wire.date_to = filters.dateTo;
685
+ if (filters.includeSoftDeleted !== void 0) wire.include_soft_deleted = filters.includeSoftDeleted;
686
+ return wire;
687
+ }
640
688
  function validateWebhook(name, url, events) {
641
689
  nonEmpty(name, "name");
642
690
  if (name.length > 128) throw new ValidationError("name may contain at most 128 characters");
@@ -700,7 +748,7 @@ var ControlPlaneClient = class {
700
748
  "User-Agent": `memorysync-sdk-js/${SDK_VERSION}`
701
749
  };
702
750
  if (requiresAuth) headers.Authorization = `Bearer ${this.accessToken}`;
703
- const selectedProject = options.projectId?.trim() ?? this.projectId;
751
+ const selectedProject = options.project === false ? void 0 : options.projectId?.trim() ?? this.projectId;
704
752
  if (selectedProject) headers["X-Project-ID"] = selectedProject;
705
753
  if (options.body !== void 0) headers["Content-Type"] = "application/json";
706
754
  const controller = new AbortController();
@@ -761,6 +809,31 @@ var ControlPlaneClient = class {
761
809
  positiveId(keyId, "keyId");
762
810
  return this.request("POST", `/org/api-keys/${keyId}/test`, options);
763
811
  }
812
+ async signup(request) {
813
+ nonEmpty(request.email, "email");
814
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(request.email)) {
815
+ throw new ValidationError("email must be a valid email address");
816
+ }
817
+ nonEmpty(request.password, "password");
818
+ if (request.password.length < 8) {
819
+ throw new ValidationError("password must contain at least 8 characters");
820
+ }
821
+ nonEmpty(request.organizationName, "organizationName");
822
+ const organizationLength = request.organizationName.trim().length;
823
+ if (organizationLength < 2 || organizationLength > 100) {
824
+ throw new ValidationError("organizationName must contain between 2 and 100 characters");
825
+ }
826
+ return this.request("POST", "/auth/signup", {
827
+ auth: false,
828
+ project: false,
829
+ body: {
830
+ email: request.email,
831
+ password: request.password,
832
+ organization_name: request.organizationName,
833
+ ...request.fullName === void 0 ? {} : { full_name: request.fullName }
834
+ }
835
+ });
836
+ }
764
837
  async login(request, options = {}) {
765
838
  nonEmpty(request.email, "email");
766
839
  nonEmpty(request.password, "password");
@@ -770,25 +843,34 @@ var ControlPlaneClient = class {
770
843
  return this.request("POST", "/auth/login", {
771
844
  ...options,
772
845
  auth: false,
846
+ project: false,
773
847
  body: { email: request.email, password: request.password }
774
848
  });
775
849
  }
776
- async getCurrentPlan(options = {}) {
777
- return this.request("GET", "/org/billing/current-plan", options);
778
- }
779
- async listTeamMembers(options = {}) {
780
- return this.request("GET", "/admin/team/members", options);
850
+ async refresh(request) {
851
+ nonEmpty(request.refreshToken, "refreshToken");
852
+ return this.request("POST", "/auth/refresh", {
853
+ auth: false,
854
+ project: false,
855
+ body: { refresh_token: request.refreshToken }
856
+ });
781
857
  }
782
- async suspendTeamMember(memberId, options = {}) {
783
- positiveId(memberId, "memberId");
784
- return this.request("PATCH", `/admin/team/members/${memberId}`, {
785
- ...options,
786
- body: { status: "suspended" }
858
+ async logout(request) {
859
+ nonEmpty(request.refreshToken, "refreshToken");
860
+ return this.request("POST", "/auth/logout", {
861
+ auth: false,
862
+ project: false,
863
+ body: { refresh_token: request.refreshToken }
787
864
  });
788
865
  }
789
- async removeTeamMember(memberId, options = {}) {
790
- positiveId(memberId, "memberId");
791
- return this.request("DELETE", `/admin/team/members/${memberId}`, options);
866
+ async me() {
867
+ return this.request("GET", "/auth/me", { project: false });
868
+ }
869
+ async logoutAll() {
870
+ return this.request("POST", "/auth/logout-all", { project: false });
871
+ }
872
+ async getCurrentPlan(options = {}) {
873
+ return this.request("GET", "/org/billing/current-plan", options);
792
874
  }
793
875
  async listSessions(options = {}) {
794
876
  return this.request("GET", "/auth/sessions", options);
@@ -797,43 +879,6 @@ var ControlPlaneClient = class {
797
879
  positiveId(sessionId, "sessionId");
798
880
  return this.request("POST", `/auth/sessions/${sessionId}/revoke`, options);
799
881
  }
800
- async listAuditEvents(query = {}, options = {}) {
801
- if (query.limit !== void 0) boundedInteger(query.limit, "limit", 1, 200);
802
- if (query.cursor !== void 0) nonNegativeInteger(query.cursor, "cursor");
803
- if (query.skip !== void 0) nonNegativeInteger(query.skip, "skip");
804
- if (query.sortDirection !== void 0 && query.sortDirection !== "asc" && query.sortDirection !== "desc") {
805
- throw new ValidationError("sortDirection must be 'asc' or 'desc'");
806
- }
807
- const path = "/admin/audit-logs" + queryString({
808
- limit: query.limit,
809
- cursor: query.cursor,
810
- skip: query.skip,
811
- sort: query.sortDirection,
812
- tenant_id: query.tenantId,
813
- actor: query.actor,
814
- actor_email: query.actorEmail,
815
- ip: query.ip,
816
- action: query.action,
817
- resource_type: query.resourceType,
818
- resource_id: query.resourceId,
819
- severity: query.severity,
820
- category: query.category,
821
- start: query.start,
822
- end: query.end,
823
- success: query.success,
824
- source: query.source,
825
- ingest_method: query.ingestMethod,
826
- search: query.search,
827
- include_stats: query.includeStats
828
- });
829
- const raw = await this.request("GET", path, options);
830
- return {
831
- events: raw.logs ?? [],
832
- nextCursor: raw.nextCursor ?? null,
833
- stats: raw.stats ?? null,
834
- sort: raw.sort ?? query.sortDirection ?? "desc"
835
- };
836
- }
837
882
  async listIntegrations(query = {}, options = {}) {
838
883
  if (query.category !== void 0) nonEmpty(query.category, "category");
839
884
  const path = "/api/v1/integrations/catalog" + queryString({ category: query.category });
@@ -849,23 +894,36 @@ var ControlPlaneClient = class {
849
894
  async listOrganizations(options = {}) {
850
895
  return this.request("GET", "/organizations", options);
851
896
  }
852
- async listOrganizationMembers(options = {}) {
853
- return this.listTeamMembers(options);
854
- }
855
- async getOrganizationSettings(query = {}, options = {}) {
856
- if (query.tenantId !== void 0) nonEmpty(query.tenantId, "tenantId");
857
- const path = "/admin/tenant-settings" + queryString({ tenant_id: query.tenantId });
858
- return this.request("GET", path, options);
859
- }
860
897
  async listProjects(options = {}) {
861
898
  return this.request("GET", "/org/projects", options);
862
899
  }
900
+ async createProject(request, options = {}) {
901
+ projectName(request.name);
902
+ return this.request("POST", "/org/projects", { ...options, body: { name: request.name } });
903
+ }
904
+ async renameProject(projectId, request, options = {}) {
905
+ const encodedId = pathId(projectId, "projectId");
906
+ projectName(request.name);
907
+ return this.request("PATCH", `/org/projects/${encodedId}`, { ...options, body: { name: request.name } });
908
+ }
909
+ async archiveProject(projectId, options = {}) {
910
+ return this.request("POST", `/org/projects/${pathId(projectId, "projectId")}/archive`, options);
911
+ }
912
+ async unarchiveProject(projectId, options = {}) {
913
+ return this.request("POST", `/org/projects/${pathId(projectId, "projectId")}/unarchive`, options);
914
+ }
915
+ async deleteProject(projectId, options = {}) {
916
+ return this.request("DELETE", `/org/projects/${pathId(projectId, "projectId")}`, options);
917
+ }
863
918
  async createWebhook(request, options = {}) {
864
919
  validateWebhook(request.name, request.url, request.events);
865
920
  if (request.description !== void 0 && request.description.length > 500) {
866
921
  throw new ValidationError("description may contain at most 500 characters");
867
922
  }
868
- if (request.projectId !== void 0) nonEmpty(request.projectId, "projectId");
923
+ if (request.projectId !== void 0) {
924
+ nonEmpty(request.projectId, "projectId");
925
+ if (request.projectId.length > 64) throw new ValidationError("projectId may contain at most 64 characters");
926
+ }
869
927
  if (options.projectId !== void 0) nonEmpty(options.projectId, "projectId override");
870
928
  if (request.projectId && options.projectId && request.projectId.trim() !== options.projectId.trim()) {
871
929
  throw new ValidationError("request projectId and options projectId must match");
@@ -884,6 +942,28 @@ var ControlPlaneClient = class {
884
942
  async listWebhooks(options = {}) {
885
943
  return this.request("GET", "/org/webhooks", options);
886
944
  }
945
+ async getWebhook(endpointId, options = {}) {
946
+ positiveId(endpointId, "endpointId");
947
+ return this.request("GET", `/org/webhooks/${endpointId}`, options);
948
+ }
949
+ async getWebhookEventTypes(options = {}) {
950
+ return this.request("GET", "/org/webhooks/event-types", options);
951
+ }
952
+ async getWebhookHealth(options = {}) {
953
+ return this.request("GET", "/org/webhooks/health", options);
954
+ }
955
+ async pauseWebhook(endpointId, options = {}) {
956
+ positiveId(endpointId, "endpointId");
957
+ return this.request("POST", `/org/webhooks/${endpointId}/pause`, options);
958
+ }
959
+ async resumeWebhook(endpointId, options = {}) {
960
+ positiveId(endpointId, "endpointId");
961
+ return this.request("POST", `/org/webhooks/${endpointId}/resume`, options);
962
+ }
963
+ async rotateWebhookSecret(endpointId, options = {}) {
964
+ positiveId(endpointId, "endpointId");
965
+ return this.request("POST", `/org/webhooks/${endpointId}/rotate-secret`, options);
966
+ }
887
967
  async updateWebhook(endpointId, request, options = {}) {
888
968
  positiveId(endpointId, "endpointId");
889
969
  const body = {};
@@ -944,9 +1024,7 @@ var ControlPlaneClient = class {
944
1024
  async listWebhookDeliveries(endpointId, query = {}, options = {}) {
945
1025
  positiveId(endpointId, "endpointId");
946
1026
  if (query.page !== void 0) positiveId(query.page, "page");
947
- if (query.pageSize !== void 0 && (!Number.isInteger(query.pageSize) || query.pageSize < 1 || query.pageSize > 100)) {
948
- throw new ValidationError("pageSize must be an integer between 1 and 100");
949
- }
1027
+ if (query.pageSize !== void 0) boundedInteger(query.pageSize, "pageSize", 1, 100);
950
1028
  if (query.status !== void 0) nonEmpty(query.status, "status");
951
1029
  const path = `/org/webhooks/${endpointId}/deliveries` + queryString({
952
1030
  page: query.page,
@@ -955,10 +1033,62 @@ var ControlPlaneClient = class {
955
1033
  });
956
1034
  return this.request("GET", path, options);
957
1035
  }
1036
+ async getLatestWebhookDelivery(endpointId, options = {}) {
1037
+ positiveId(endpointId, "endpointId");
1038
+ return this.request("GET", `/org/webhooks/${endpointId}/deliveries/latest`, options);
1039
+ }
1040
+ async listRecentWebhookDeliveries(query = {}, options = {}) {
1041
+ if (query.page !== void 0) positiveId(query.page, "page");
1042
+ if (query.pageSize !== void 0) boundedInteger(query.pageSize, "pageSize", 1, 100);
1043
+ if (query.endpointId !== void 0) positiveId(query.endpointId, "endpointId");
1044
+ if (query.status !== void 0) nonEmpty(query.status, "status");
1045
+ const path = "/org/webhooks/deliveries/recent" + queryString({
1046
+ page: query.page,
1047
+ page_size: query.pageSize,
1048
+ endpoint_id: query.endpointId,
1049
+ status_filter: query.status
1050
+ });
1051
+ return this.request("GET", path, options);
1052
+ }
1053
+ async getWebhookDelivery(deliveryId, options = {}) {
1054
+ positiveId(deliveryId, "deliveryId");
1055
+ return this.request("GET", `/org/webhooks/deliveries/${deliveryId}`, options);
1056
+ }
1057
+ async retryWebhookDelivery(deliveryId, options = {}) {
1058
+ positiveId(deliveryId, "deliveryId");
1059
+ return this.request("POST", `/org/webhooks/deliveries/${deliveryId}/retry`, options);
1060
+ }
1061
+ async createExport(request, options = {}) {
1062
+ const format = request.format ?? "csv";
1063
+ const scope = request.scope ?? "filtered";
1064
+ if (format !== "csv" && format !== "jsonl") throw new ValidationError("format must be 'csv' or 'jsonl'");
1065
+ if (scope !== "filtered" && scope !== "all" && scope !== "date_range") {
1066
+ throw new ValidationError("scope must be 'filtered', 'all', or 'date_range'");
1067
+ }
1068
+ const body = { format, scope };
1069
+ if (request.filters !== void 0) body.filters = request.filters === null ? null : exportFilters(request.filters);
1070
+ return this.request("POST", "/exports", { ...options, body });
1071
+ }
1072
+ async listExports(query = {}, options = {}) {
1073
+ if (query.limit !== void 0) boundedInteger(query.limit, "limit", 1, 100);
1074
+ return this.request("GET", "/exports" + queryString({ limit: query.limit }), options);
1075
+ }
1076
+ async getExport(jobId, options = {}) {
1077
+ return this.request("GET", `/exports/${pathId(jobId, "jobId", 8, 64)}`, options);
1078
+ }
1079
+ async cancelExport(jobId, options = {}) {
1080
+ return this.request("POST", `/exports/${pathId(jobId, "jobId", 8, 64)}/cancel`, options);
1081
+ }
1082
+ async retryExport(jobId, options = {}) {
1083
+ return this.request("POST", `/exports/${pathId(jobId, "jobId", 8, 64)}/retry`, options);
1084
+ }
1085
+ async getExportDownloadUrl(jobId, options = {}) {
1086
+ return this.request("GET", `/exports/${pathId(jobId, "jobId", 8, 64)}/download-url`, options);
1087
+ }
958
1088
  };
959
1089
 
960
1090
  // src/index.ts
961
- var SDK_VERSION2 = "1.4.0";
1091
+ var SDK_VERSION2 = "1.6.0";
962
1092
  function camelToSnakeKey(key) {
963
1093
  return key.replace(/([A-Z])/g, "_$1").toLowerCase();
964
1094
  }