memorysync-sdk 1.4.0 → 1.5.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.5.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");
@@ -820,20 +868,6 @@ var ControlPlaneClient = class {
820
868
  async getCurrentPlan(options = {}) {
821
869
  return this.request("GET", "/org/billing/current-plan", options);
822
870
  }
823
- async listTeamMembers(options = {}) {
824
- return this.request("GET", "/admin/team/members", options);
825
- }
826
- async suspendTeamMember(memberId, options = {}) {
827
- positiveId(memberId, "memberId");
828
- return this.request("PATCH", `/admin/team/members/${memberId}`, {
829
- ...options,
830
- body: { status: "suspended" }
831
- });
832
- }
833
- async removeTeamMember(memberId, options = {}) {
834
- positiveId(memberId, "memberId");
835
- return this.request("DELETE", `/admin/team/members/${memberId}`, options);
836
- }
837
871
  async listSessions(options = {}) {
838
872
  return this.request("GET", "/auth/sessions", options);
839
873
  }
@@ -841,43 +875,6 @@ var ControlPlaneClient = class {
841
875
  positiveId(sessionId, "sessionId");
842
876
  return this.request("POST", `/auth/sessions/${sessionId}/revoke`, options);
843
877
  }
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
878
  async listIntegrations(query = {}, options = {}) {
882
879
  if (query.category !== void 0) nonEmpty(query.category, "category");
883
880
  const path = "/api/v1/integrations/catalog" + queryString({ category: query.category });
@@ -893,23 +890,36 @@ var ControlPlaneClient = class {
893
890
  async listOrganizations(options = {}) {
894
891
  return this.request("GET", "/organizations", options);
895
892
  }
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
893
  async listProjects(options = {}) {
905
894
  return this.request("GET", "/org/projects", options);
906
895
  }
896
+ async createProject(request, options = {}) {
897
+ projectName(request.name);
898
+ return this.request("POST", "/org/projects", { ...options, body: { name: request.name } });
899
+ }
900
+ async renameProject(projectId, request, options = {}) {
901
+ const encodedId = pathId(projectId, "projectId");
902
+ projectName(request.name);
903
+ return this.request("PATCH", `/org/projects/${encodedId}`, { ...options, body: { name: request.name } });
904
+ }
905
+ async archiveProject(projectId, options = {}) {
906
+ return this.request("POST", `/org/projects/${pathId(projectId, "projectId")}/archive`, options);
907
+ }
908
+ async unarchiveProject(projectId, options = {}) {
909
+ return this.request("POST", `/org/projects/${pathId(projectId, "projectId")}/unarchive`, options);
910
+ }
911
+ async deleteProject(projectId, options = {}) {
912
+ return this.request("DELETE", `/org/projects/${pathId(projectId, "projectId")}`, options);
913
+ }
907
914
  async createWebhook(request, options = {}) {
908
915
  validateWebhook(request.name, request.url, request.events);
909
916
  if (request.description !== void 0 && request.description.length > 500) {
910
917
  throw new ValidationError("description may contain at most 500 characters");
911
918
  }
912
- if (request.projectId !== void 0) nonEmpty(request.projectId, "projectId");
919
+ if (request.projectId !== void 0) {
920
+ nonEmpty(request.projectId, "projectId");
921
+ if (request.projectId.length > 64) throw new ValidationError("projectId may contain at most 64 characters");
922
+ }
913
923
  if (options.projectId !== void 0) nonEmpty(options.projectId, "projectId override");
914
924
  if (request.projectId && options.projectId && request.projectId.trim() !== options.projectId.trim()) {
915
925
  throw new ValidationError("request projectId and options projectId must match");
@@ -928,6 +938,28 @@ var ControlPlaneClient = class {
928
938
  async listWebhooks(options = {}) {
929
939
  return this.request("GET", "/org/webhooks", options);
930
940
  }
941
+ async getWebhook(endpointId, options = {}) {
942
+ positiveId(endpointId, "endpointId");
943
+ return this.request("GET", `/org/webhooks/${endpointId}`, options);
944
+ }
945
+ async getWebhookEventTypes(options = {}) {
946
+ return this.request("GET", "/org/webhooks/event-types", options);
947
+ }
948
+ async getWebhookHealth(options = {}) {
949
+ return this.request("GET", "/org/webhooks/health", options);
950
+ }
951
+ async pauseWebhook(endpointId, options = {}) {
952
+ positiveId(endpointId, "endpointId");
953
+ return this.request("POST", `/org/webhooks/${endpointId}/pause`, options);
954
+ }
955
+ async resumeWebhook(endpointId, options = {}) {
956
+ positiveId(endpointId, "endpointId");
957
+ return this.request("POST", `/org/webhooks/${endpointId}/resume`, options);
958
+ }
959
+ async rotateWebhookSecret(endpointId, options = {}) {
960
+ positiveId(endpointId, "endpointId");
961
+ return this.request("POST", `/org/webhooks/${endpointId}/rotate-secret`, options);
962
+ }
931
963
  async updateWebhook(endpointId, request, options = {}) {
932
964
  positiveId(endpointId, "endpointId");
933
965
  const body = {};
@@ -988,9 +1020,7 @@ var ControlPlaneClient = class {
988
1020
  async listWebhookDeliveries(endpointId, query = {}, options = {}) {
989
1021
  positiveId(endpointId, "endpointId");
990
1022
  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
- }
1023
+ if (query.pageSize !== void 0) boundedInteger(query.pageSize, "pageSize", 1, 100);
994
1024
  if (query.status !== void 0) nonEmpty(query.status, "status");
995
1025
  const path = `/org/webhooks/${endpointId}/deliveries` + queryString({
996
1026
  page: query.page,
@@ -999,10 +1029,62 @@ var ControlPlaneClient = class {
999
1029
  });
1000
1030
  return this.request("GET", path, options);
1001
1031
  }
1032
+ async getLatestWebhookDelivery(endpointId, options = {}) {
1033
+ positiveId(endpointId, "endpointId");
1034
+ return this.request("GET", `/org/webhooks/${endpointId}/deliveries/latest`, options);
1035
+ }
1036
+ async listRecentWebhookDeliveries(query = {}, options = {}) {
1037
+ if (query.page !== void 0) positiveId(query.page, "page");
1038
+ if (query.pageSize !== void 0) boundedInteger(query.pageSize, "pageSize", 1, 100);
1039
+ if (query.endpointId !== void 0) positiveId(query.endpointId, "endpointId");
1040
+ if (query.status !== void 0) nonEmpty(query.status, "status");
1041
+ const path = "/org/webhooks/deliveries/recent" + queryString({
1042
+ page: query.page,
1043
+ page_size: query.pageSize,
1044
+ endpoint_id: query.endpointId,
1045
+ status_filter: query.status
1046
+ });
1047
+ return this.request("GET", path, options);
1048
+ }
1049
+ async getWebhookDelivery(deliveryId, options = {}) {
1050
+ positiveId(deliveryId, "deliveryId");
1051
+ return this.request("GET", `/org/webhooks/deliveries/${deliveryId}`, options);
1052
+ }
1053
+ async retryWebhookDelivery(deliveryId, options = {}) {
1054
+ positiveId(deliveryId, "deliveryId");
1055
+ return this.request("POST", `/org/webhooks/deliveries/${deliveryId}/retry`, options);
1056
+ }
1057
+ async createExport(request, options = {}) {
1058
+ const format = request.format ?? "csv";
1059
+ const scope = request.scope ?? "filtered";
1060
+ if (format !== "csv" && format !== "jsonl") throw new ValidationError("format must be 'csv' or 'jsonl'");
1061
+ if (scope !== "filtered" && scope !== "all" && scope !== "date_range") {
1062
+ throw new ValidationError("scope must be 'filtered', 'all', or 'date_range'");
1063
+ }
1064
+ const body = { format, scope };
1065
+ if (request.filters !== void 0) body.filters = request.filters === null ? null : exportFilters(request.filters);
1066
+ return this.request("POST", "/exports", { ...options, body });
1067
+ }
1068
+ async listExports(query = {}, options = {}) {
1069
+ if (query.limit !== void 0) boundedInteger(query.limit, "limit", 1, 100);
1070
+ return this.request("GET", "/exports" + queryString({ limit: query.limit }), options);
1071
+ }
1072
+ async getExport(jobId, options = {}) {
1073
+ return this.request("GET", `/exports/${pathId(jobId, "jobId", 8, 64)}`, options);
1074
+ }
1075
+ async cancelExport(jobId, options = {}) {
1076
+ return this.request("POST", `/exports/${pathId(jobId, "jobId", 8, 64)}/cancel`, options);
1077
+ }
1078
+ async retryExport(jobId, options = {}) {
1079
+ return this.request("POST", `/exports/${pathId(jobId, "jobId", 8, 64)}/retry`, options);
1080
+ }
1081
+ async getExportDownloadUrl(jobId, options = {}) {
1082
+ return this.request("GET", `/exports/${pathId(jobId, "jobId", 8, 64)}/download-url`, options);
1083
+ }
1002
1084
  };
1003
1085
 
1004
1086
  // src/index.ts
1005
- var SDK_VERSION2 = "1.4.0";
1087
+ var SDK_VERSION2 = "1.5.0";
1006
1088
  function camelToSnakeKey(key) {
1007
1089
  return key.replace(/([A-Z])/g, "_$1").toLowerCase();
1008
1090
  }