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.js CHANGED
@@ -576,7 +576,7 @@ var IntegrationsNamespace = class extends Namespace {
576
576
  };
577
577
 
578
578
  // src/control-plane.ts
579
- var SDK_VERSION = "1.4.0";
579
+ var SDK_VERSION = "1.6.0";
580
580
  function safeJson(text) {
581
581
  try {
582
582
  return JSON.parse(text);
@@ -653,17 +653,51 @@ function boundedInteger(value, name, minimum, maximum) {
653
653
  throw new ValidationError(`${name} must be an integer between ${minimum} and ${maximum}`);
654
654
  }
655
655
  }
656
- function nonNegativeInteger(value, name) {
657
- if (!Number.isInteger(value) || value < 0) {
658
- throw new ValidationError(`${name} must be a non-negative integer`);
659
- }
660
- }
661
656
  function nonEmptyStrings(values, name) {
662
657
  if (!Array.isArray(values) || values.length === 0 || values.some((value) => typeof value !== "string" || !value.trim())) {
663
658
  throw new ValidationError(`${name} must contain at least one non-empty string`);
664
659
  }
665
660
  }
661
+ function projectName(value) {
662
+ nonEmpty(value, "name");
663
+ if (value.length > 200) throw new ValidationError("name may contain at most 200 characters");
664
+ }
665
+ function pathId(value, name, minimum = 1, maximum) {
666
+ nonEmpty(value, name);
667
+ const trimmed = value.trim();
668
+ if (trimmed.length < minimum || maximum !== void 0 && trimmed.length > maximum) {
669
+ const range = maximum === void 0 ? `at least ${minimum}` : `between ${minimum} and ${maximum}`;
670
+ throw new ValidationError(`${name} must contain ${range} characters`);
671
+ }
672
+ return encodeURIComponent(trimmed);
673
+ }
674
+ function validateWebhookRetryConfig(config) {
675
+ if (config.maxRetries !== void 0) boundedInteger(config.maxRetries, "maxRetries", 1, 10);
676
+ if (config.initialDelaySeconds !== void 0) boundedInteger(config.initialDelaySeconds, "initialDelaySeconds", 1, 60);
677
+ if (config.maxDelaySeconds !== void 0) boundedInteger(config.maxDelaySeconds, "maxDelaySeconds", 60, 86400);
678
+ if (config.backoffMultiplier !== void 0 && (!Number.isFinite(config.backoffMultiplier) || config.backoffMultiplier < 1 || config.backoffMultiplier > 5)) {
679
+ throw new ValidationError("backoffMultiplier must be between 1 and 5");
680
+ }
681
+ if (config.retryStatusCodes !== void 0 && (!Array.isArray(config.retryStatusCodes) || config.retryStatusCodes.length === 0 || config.retryStatusCodes.some((value) => typeof value !== "string" || value.trim().length === 0))) {
682
+ throw new ValidationError("retryStatusCodes must contain at least one non-empty string");
683
+ }
684
+ }
685
+ function validateWebhookSignatureConfig(config) {
686
+ if (config.algorithm !== void 0 && config.algorithm !== "hmac-sha256" && config.algorithm !== "hmac-sha512") {
687
+ throw new ValidationError("algorithm must be 'hmac-sha256' or 'hmac-sha512'");
688
+ }
689
+ for (const [name, value] of [["headerName", config.headerName], ["timestampHeader", config.timestampHeader]]) {
690
+ if (value !== void 0 && value.trim().length === 0) {
691
+ throw new ValidationError(`${name} must be a non-empty string`);
692
+ }
693
+ if (value !== void 0 && value.length > 64) {
694
+ throw new ValidationError(`${name} may contain at most 64 characters`);
695
+ }
696
+ }
697
+ if (config.toleranceSeconds !== void 0) boundedInteger(config.toleranceSeconds, "toleranceSeconds", 60, 3600);
698
+ }
666
699
  function webhookRetryConfig(config) {
700
+ validateWebhookRetryConfig(config);
667
701
  const wire = {};
668
702
  if (config.enabled !== void 0) wire.enabled = config.enabled;
669
703
  if (config.maxRetries !== void 0) wire.max_retries = config.maxRetries;
@@ -674,6 +708,7 @@ function webhookRetryConfig(config) {
674
708
  return wire;
675
709
  }
676
710
  function webhookSignatureConfig(config) {
711
+ validateWebhookSignatureConfig(config);
677
712
  const wire = {};
678
713
  if (config.algorithm !== void 0) wire.algorithm = config.algorithm;
679
714
  if (config.headerName !== void 0) wire.header_name = config.headerName;
@@ -681,6 +716,19 @@ function webhookSignatureConfig(config) {
681
716
  if (config.toleranceSeconds !== void 0) wire.tolerance_seconds = config.toleranceSeconds;
682
717
  return wire;
683
718
  }
719
+ function exportFilters(filters) {
720
+ const wire = {};
721
+ if (filters.q !== void 0) wire.q = filters.q;
722
+ if (filters.userId !== void 0) wire.user_id = filters.userId;
723
+ if (filters.isSummary !== void 0) wire.is_summary = filters.isSummary;
724
+ if (filters.tier !== void 0) wire.tier = filters.tier;
725
+ if (filters.source !== void 0) wire.source = filters.source;
726
+ if (filters.timeRange !== void 0) wire.time_range = filters.timeRange;
727
+ if (filters.dateFrom !== void 0) wire.date_from = filters.dateFrom;
728
+ if (filters.dateTo !== void 0) wire.date_to = filters.dateTo;
729
+ if (filters.includeSoftDeleted !== void 0) wire.include_soft_deleted = filters.includeSoftDeleted;
730
+ return wire;
731
+ }
684
732
  function validateWebhook(name, url, events) {
685
733
  nonEmpty(name, "name");
686
734
  if (name.length > 128) throw new ValidationError("name may contain at most 128 characters");
@@ -744,7 +792,7 @@ var ControlPlaneClient = class {
744
792
  "User-Agent": `memorysync-sdk-js/${SDK_VERSION}`
745
793
  };
746
794
  if (requiresAuth) headers.Authorization = `Bearer ${this.accessToken}`;
747
- const selectedProject = options.projectId?.trim() ?? this.projectId;
795
+ const selectedProject = options.project === false ? void 0 : options.projectId?.trim() ?? this.projectId;
748
796
  if (selectedProject) headers["X-Project-ID"] = selectedProject;
749
797
  if (options.body !== void 0) headers["Content-Type"] = "application/json";
750
798
  const controller = new AbortController();
@@ -805,6 +853,31 @@ var ControlPlaneClient = class {
805
853
  positiveId(keyId, "keyId");
806
854
  return this.request("POST", `/org/api-keys/${keyId}/test`, options);
807
855
  }
856
+ async signup(request) {
857
+ nonEmpty(request.email, "email");
858
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(request.email)) {
859
+ throw new ValidationError("email must be a valid email address");
860
+ }
861
+ nonEmpty(request.password, "password");
862
+ if (request.password.length < 8) {
863
+ throw new ValidationError("password must contain at least 8 characters");
864
+ }
865
+ nonEmpty(request.organizationName, "organizationName");
866
+ const organizationLength = request.organizationName.trim().length;
867
+ if (organizationLength < 2 || organizationLength > 100) {
868
+ throw new ValidationError("organizationName must contain between 2 and 100 characters");
869
+ }
870
+ return this.request("POST", "/auth/signup", {
871
+ auth: false,
872
+ project: false,
873
+ body: {
874
+ email: request.email,
875
+ password: request.password,
876
+ organization_name: request.organizationName,
877
+ ...request.fullName === void 0 ? {} : { full_name: request.fullName }
878
+ }
879
+ });
880
+ }
808
881
  async login(request, options = {}) {
809
882
  nonEmpty(request.email, "email");
810
883
  nonEmpty(request.password, "password");
@@ -814,25 +887,34 @@ var ControlPlaneClient = class {
814
887
  return this.request("POST", "/auth/login", {
815
888
  ...options,
816
889
  auth: false,
890
+ project: false,
817
891
  body: { email: request.email, password: request.password }
818
892
  });
819
893
  }
820
- async getCurrentPlan(options = {}) {
821
- return this.request("GET", "/org/billing/current-plan", options);
822
- }
823
- async listTeamMembers(options = {}) {
824
- return this.request("GET", "/admin/team/members", options);
894
+ async refresh(request) {
895
+ nonEmpty(request.refreshToken, "refreshToken");
896
+ return this.request("POST", "/auth/refresh", {
897
+ auth: false,
898
+ project: false,
899
+ body: { refresh_token: request.refreshToken }
900
+ });
825
901
  }
826
- async suspendTeamMember(memberId, options = {}) {
827
- positiveId(memberId, "memberId");
828
- return this.request("PATCH", `/admin/team/members/${memberId}`, {
829
- ...options,
830
- body: { status: "suspended" }
902
+ async logout(request) {
903
+ nonEmpty(request.refreshToken, "refreshToken");
904
+ return this.request("POST", "/auth/logout", {
905
+ auth: false,
906
+ project: false,
907
+ body: { refresh_token: request.refreshToken }
831
908
  });
832
909
  }
833
- async removeTeamMember(memberId, options = {}) {
834
- positiveId(memberId, "memberId");
835
- return this.request("DELETE", `/admin/team/members/${memberId}`, options);
910
+ async me() {
911
+ return this.request("GET", "/auth/me", { project: false });
912
+ }
913
+ async logoutAll() {
914
+ return this.request("POST", "/auth/logout-all", { project: false });
915
+ }
916
+ async getCurrentPlan(options = {}) {
917
+ return this.request("GET", "/org/billing/current-plan", options);
836
918
  }
837
919
  async listSessions(options = {}) {
838
920
  return this.request("GET", "/auth/sessions", options);
@@ -841,43 +923,6 @@ var ControlPlaneClient = class {
841
923
  positiveId(sessionId, "sessionId");
842
924
  return this.request("POST", `/auth/sessions/${sessionId}/revoke`, options);
843
925
  }
844
- async listAuditEvents(query = {}, options = {}) {
845
- if (query.limit !== void 0) boundedInteger(query.limit, "limit", 1, 200);
846
- if (query.cursor !== void 0) nonNegativeInteger(query.cursor, "cursor");
847
- if (query.skip !== void 0) nonNegativeInteger(query.skip, "skip");
848
- if (query.sortDirection !== void 0 && query.sortDirection !== "asc" && query.sortDirection !== "desc") {
849
- throw new ValidationError("sortDirection must be 'asc' or 'desc'");
850
- }
851
- const path = "/admin/audit-logs" + queryString({
852
- limit: query.limit,
853
- cursor: query.cursor,
854
- skip: query.skip,
855
- sort: query.sortDirection,
856
- tenant_id: query.tenantId,
857
- actor: query.actor,
858
- actor_email: query.actorEmail,
859
- ip: query.ip,
860
- action: query.action,
861
- resource_type: query.resourceType,
862
- resource_id: query.resourceId,
863
- severity: query.severity,
864
- category: query.category,
865
- start: query.start,
866
- end: query.end,
867
- success: query.success,
868
- source: query.source,
869
- ingest_method: query.ingestMethod,
870
- search: query.search,
871
- include_stats: query.includeStats
872
- });
873
- const raw = await this.request("GET", path, options);
874
- return {
875
- events: raw.logs ?? [],
876
- nextCursor: raw.nextCursor ?? null,
877
- stats: raw.stats ?? null,
878
- sort: raw.sort ?? query.sortDirection ?? "desc"
879
- };
880
- }
881
926
  async listIntegrations(query = {}, options = {}) {
882
927
  if (query.category !== void 0) nonEmpty(query.category, "category");
883
928
  const path = "/api/v1/integrations/catalog" + queryString({ category: query.category });
@@ -893,23 +938,36 @@ var ControlPlaneClient = class {
893
938
  async listOrganizations(options = {}) {
894
939
  return this.request("GET", "/organizations", options);
895
940
  }
896
- async listOrganizationMembers(options = {}) {
897
- return this.listTeamMembers(options);
898
- }
899
- async getOrganizationSettings(query = {}, options = {}) {
900
- if (query.tenantId !== void 0) nonEmpty(query.tenantId, "tenantId");
901
- const path = "/admin/tenant-settings" + queryString({ tenant_id: query.tenantId });
902
- return this.request("GET", path, options);
903
- }
904
941
  async listProjects(options = {}) {
905
942
  return this.request("GET", "/org/projects", options);
906
943
  }
944
+ async createProject(request, options = {}) {
945
+ projectName(request.name);
946
+ return this.request("POST", "/org/projects", { ...options, body: { name: request.name } });
947
+ }
948
+ async renameProject(projectId, request, options = {}) {
949
+ const encodedId = pathId(projectId, "projectId");
950
+ projectName(request.name);
951
+ return this.request("PATCH", `/org/projects/${encodedId}`, { ...options, body: { name: request.name } });
952
+ }
953
+ async archiveProject(projectId, options = {}) {
954
+ return this.request("POST", `/org/projects/${pathId(projectId, "projectId")}/archive`, options);
955
+ }
956
+ async unarchiveProject(projectId, options = {}) {
957
+ return this.request("POST", `/org/projects/${pathId(projectId, "projectId")}/unarchive`, options);
958
+ }
959
+ async deleteProject(projectId, options = {}) {
960
+ return this.request("DELETE", `/org/projects/${pathId(projectId, "projectId")}`, options);
961
+ }
907
962
  async createWebhook(request, options = {}) {
908
963
  validateWebhook(request.name, request.url, request.events);
909
964
  if (request.description !== void 0 && request.description.length > 500) {
910
965
  throw new ValidationError("description may contain at most 500 characters");
911
966
  }
912
- if (request.projectId !== void 0) nonEmpty(request.projectId, "projectId");
967
+ if (request.projectId !== void 0) {
968
+ nonEmpty(request.projectId, "projectId");
969
+ if (request.projectId.length > 64) throw new ValidationError("projectId may contain at most 64 characters");
970
+ }
913
971
  if (options.projectId !== void 0) nonEmpty(options.projectId, "projectId override");
914
972
  if (request.projectId && options.projectId && request.projectId.trim() !== options.projectId.trim()) {
915
973
  throw new ValidationError("request projectId and options projectId must match");
@@ -928,6 +986,28 @@ var ControlPlaneClient = class {
928
986
  async listWebhooks(options = {}) {
929
987
  return this.request("GET", "/org/webhooks", options);
930
988
  }
989
+ async getWebhook(endpointId, options = {}) {
990
+ positiveId(endpointId, "endpointId");
991
+ return this.request("GET", `/org/webhooks/${endpointId}`, options);
992
+ }
993
+ async getWebhookEventTypes(options = {}) {
994
+ return this.request("GET", "/org/webhooks/event-types", options);
995
+ }
996
+ async getWebhookHealth(options = {}) {
997
+ return this.request("GET", "/org/webhooks/health", options);
998
+ }
999
+ async pauseWebhook(endpointId, options = {}) {
1000
+ positiveId(endpointId, "endpointId");
1001
+ return this.request("POST", `/org/webhooks/${endpointId}/pause`, options);
1002
+ }
1003
+ async resumeWebhook(endpointId, options = {}) {
1004
+ positiveId(endpointId, "endpointId");
1005
+ return this.request("POST", `/org/webhooks/${endpointId}/resume`, options);
1006
+ }
1007
+ async rotateWebhookSecret(endpointId, options = {}) {
1008
+ positiveId(endpointId, "endpointId");
1009
+ return this.request("POST", `/org/webhooks/${endpointId}/rotate-secret`, options);
1010
+ }
931
1011
  async updateWebhook(endpointId, request, options = {}) {
932
1012
  positiveId(endpointId, "endpointId");
933
1013
  const body = {};
@@ -988,9 +1068,7 @@ var ControlPlaneClient = class {
988
1068
  async listWebhookDeliveries(endpointId, query = {}, options = {}) {
989
1069
  positiveId(endpointId, "endpointId");
990
1070
  if (query.page !== void 0) positiveId(query.page, "page");
991
- if (query.pageSize !== void 0 && (!Number.isInteger(query.pageSize) || query.pageSize < 1 || query.pageSize > 100)) {
992
- throw new ValidationError("pageSize must be an integer between 1 and 100");
993
- }
1071
+ if (query.pageSize !== void 0) boundedInteger(query.pageSize, "pageSize", 1, 100);
994
1072
  if (query.status !== void 0) nonEmpty(query.status, "status");
995
1073
  const path = `/org/webhooks/${endpointId}/deliveries` + queryString({
996
1074
  page: query.page,
@@ -999,10 +1077,62 @@ var ControlPlaneClient = class {
999
1077
  });
1000
1078
  return this.request("GET", path, options);
1001
1079
  }
1080
+ async getLatestWebhookDelivery(endpointId, options = {}) {
1081
+ positiveId(endpointId, "endpointId");
1082
+ return this.request("GET", `/org/webhooks/${endpointId}/deliveries/latest`, options);
1083
+ }
1084
+ async listRecentWebhookDeliveries(query = {}, options = {}) {
1085
+ if (query.page !== void 0) positiveId(query.page, "page");
1086
+ if (query.pageSize !== void 0) boundedInteger(query.pageSize, "pageSize", 1, 100);
1087
+ if (query.endpointId !== void 0) positiveId(query.endpointId, "endpointId");
1088
+ if (query.status !== void 0) nonEmpty(query.status, "status");
1089
+ const path = "/org/webhooks/deliveries/recent" + queryString({
1090
+ page: query.page,
1091
+ page_size: query.pageSize,
1092
+ endpoint_id: query.endpointId,
1093
+ status_filter: query.status
1094
+ });
1095
+ return this.request("GET", path, options);
1096
+ }
1097
+ async getWebhookDelivery(deliveryId, options = {}) {
1098
+ positiveId(deliveryId, "deliveryId");
1099
+ return this.request("GET", `/org/webhooks/deliveries/${deliveryId}`, options);
1100
+ }
1101
+ async retryWebhookDelivery(deliveryId, options = {}) {
1102
+ positiveId(deliveryId, "deliveryId");
1103
+ return this.request("POST", `/org/webhooks/deliveries/${deliveryId}/retry`, options);
1104
+ }
1105
+ async createExport(request, options = {}) {
1106
+ const format = request.format ?? "csv";
1107
+ const scope = request.scope ?? "filtered";
1108
+ if (format !== "csv" && format !== "jsonl") throw new ValidationError("format must be 'csv' or 'jsonl'");
1109
+ if (scope !== "filtered" && scope !== "all" && scope !== "date_range") {
1110
+ throw new ValidationError("scope must be 'filtered', 'all', or 'date_range'");
1111
+ }
1112
+ const body = { format, scope };
1113
+ if (request.filters !== void 0) body.filters = request.filters === null ? null : exportFilters(request.filters);
1114
+ return this.request("POST", "/exports", { ...options, body });
1115
+ }
1116
+ async listExports(query = {}, options = {}) {
1117
+ if (query.limit !== void 0) boundedInteger(query.limit, "limit", 1, 100);
1118
+ return this.request("GET", "/exports" + queryString({ limit: query.limit }), options);
1119
+ }
1120
+ async getExport(jobId, options = {}) {
1121
+ return this.request("GET", `/exports/${pathId(jobId, "jobId", 8, 64)}`, options);
1122
+ }
1123
+ async cancelExport(jobId, options = {}) {
1124
+ return this.request("POST", `/exports/${pathId(jobId, "jobId", 8, 64)}/cancel`, options);
1125
+ }
1126
+ async retryExport(jobId, options = {}) {
1127
+ return this.request("POST", `/exports/${pathId(jobId, "jobId", 8, 64)}/retry`, options);
1128
+ }
1129
+ async getExportDownloadUrl(jobId, options = {}) {
1130
+ return this.request("GET", `/exports/${pathId(jobId, "jobId", 8, 64)}/download-url`, options);
1131
+ }
1002
1132
  };
1003
1133
 
1004
1134
  // src/index.ts
1005
- var SDK_VERSION2 = "1.4.0";
1135
+ var SDK_VERSION2 = "1.6.0";
1006
1136
  function camelToSnakeKey(key) {
1007
1137
  return key.replace(/([A-Z])/g, "_$1").toLowerCase();
1008
1138
  }