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.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.5.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");
@@ -776,20 +824,6 @@ var ControlPlaneClient = class {
776
824
  async getCurrentPlan(options = {}) {
777
825
  return this.request("GET", "/org/billing/current-plan", options);
778
826
  }
779
- async listTeamMembers(options = {}) {
780
- return this.request("GET", "/admin/team/members", options);
781
- }
782
- async suspendTeamMember(memberId, options = {}) {
783
- positiveId(memberId, "memberId");
784
- return this.request("PATCH", `/admin/team/members/${memberId}`, {
785
- ...options,
786
- body: { status: "suspended" }
787
- });
788
- }
789
- async removeTeamMember(memberId, options = {}) {
790
- positiveId(memberId, "memberId");
791
- return this.request("DELETE", `/admin/team/members/${memberId}`, options);
792
- }
793
827
  async listSessions(options = {}) {
794
828
  return this.request("GET", "/auth/sessions", options);
795
829
  }
@@ -797,43 +831,6 @@ var ControlPlaneClient = class {
797
831
  positiveId(sessionId, "sessionId");
798
832
  return this.request("POST", `/auth/sessions/${sessionId}/revoke`, options);
799
833
  }
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
834
  async listIntegrations(query = {}, options = {}) {
838
835
  if (query.category !== void 0) nonEmpty(query.category, "category");
839
836
  const path = "/api/v1/integrations/catalog" + queryString({ category: query.category });
@@ -849,23 +846,36 @@ var ControlPlaneClient = class {
849
846
  async listOrganizations(options = {}) {
850
847
  return this.request("GET", "/organizations", options);
851
848
  }
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
849
  async listProjects(options = {}) {
861
850
  return this.request("GET", "/org/projects", options);
862
851
  }
852
+ async createProject(request, options = {}) {
853
+ projectName(request.name);
854
+ return this.request("POST", "/org/projects", { ...options, body: { name: request.name } });
855
+ }
856
+ async renameProject(projectId, request, options = {}) {
857
+ const encodedId = pathId(projectId, "projectId");
858
+ projectName(request.name);
859
+ return this.request("PATCH", `/org/projects/${encodedId}`, { ...options, body: { name: request.name } });
860
+ }
861
+ async archiveProject(projectId, options = {}) {
862
+ return this.request("POST", `/org/projects/${pathId(projectId, "projectId")}/archive`, options);
863
+ }
864
+ async unarchiveProject(projectId, options = {}) {
865
+ return this.request("POST", `/org/projects/${pathId(projectId, "projectId")}/unarchive`, options);
866
+ }
867
+ async deleteProject(projectId, options = {}) {
868
+ return this.request("DELETE", `/org/projects/${pathId(projectId, "projectId")}`, options);
869
+ }
863
870
  async createWebhook(request, options = {}) {
864
871
  validateWebhook(request.name, request.url, request.events);
865
872
  if (request.description !== void 0 && request.description.length > 500) {
866
873
  throw new ValidationError("description may contain at most 500 characters");
867
874
  }
868
- if (request.projectId !== void 0) nonEmpty(request.projectId, "projectId");
875
+ if (request.projectId !== void 0) {
876
+ nonEmpty(request.projectId, "projectId");
877
+ if (request.projectId.length > 64) throw new ValidationError("projectId may contain at most 64 characters");
878
+ }
869
879
  if (options.projectId !== void 0) nonEmpty(options.projectId, "projectId override");
870
880
  if (request.projectId && options.projectId && request.projectId.trim() !== options.projectId.trim()) {
871
881
  throw new ValidationError("request projectId and options projectId must match");
@@ -884,6 +894,28 @@ var ControlPlaneClient = class {
884
894
  async listWebhooks(options = {}) {
885
895
  return this.request("GET", "/org/webhooks", options);
886
896
  }
897
+ async getWebhook(endpointId, options = {}) {
898
+ positiveId(endpointId, "endpointId");
899
+ return this.request("GET", `/org/webhooks/${endpointId}`, options);
900
+ }
901
+ async getWebhookEventTypes(options = {}) {
902
+ return this.request("GET", "/org/webhooks/event-types", options);
903
+ }
904
+ async getWebhookHealth(options = {}) {
905
+ return this.request("GET", "/org/webhooks/health", options);
906
+ }
907
+ async pauseWebhook(endpointId, options = {}) {
908
+ positiveId(endpointId, "endpointId");
909
+ return this.request("POST", `/org/webhooks/${endpointId}/pause`, options);
910
+ }
911
+ async resumeWebhook(endpointId, options = {}) {
912
+ positiveId(endpointId, "endpointId");
913
+ return this.request("POST", `/org/webhooks/${endpointId}/resume`, options);
914
+ }
915
+ async rotateWebhookSecret(endpointId, options = {}) {
916
+ positiveId(endpointId, "endpointId");
917
+ return this.request("POST", `/org/webhooks/${endpointId}/rotate-secret`, options);
918
+ }
887
919
  async updateWebhook(endpointId, request, options = {}) {
888
920
  positiveId(endpointId, "endpointId");
889
921
  const body = {};
@@ -944,9 +976,7 @@ var ControlPlaneClient = class {
944
976
  async listWebhookDeliveries(endpointId, query = {}, options = {}) {
945
977
  positiveId(endpointId, "endpointId");
946
978
  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
- }
979
+ if (query.pageSize !== void 0) boundedInteger(query.pageSize, "pageSize", 1, 100);
950
980
  if (query.status !== void 0) nonEmpty(query.status, "status");
951
981
  const path = `/org/webhooks/${endpointId}/deliveries` + queryString({
952
982
  page: query.page,
@@ -955,10 +985,62 @@ var ControlPlaneClient = class {
955
985
  });
956
986
  return this.request("GET", path, options);
957
987
  }
988
+ async getLatestWebhookDelivery(endpointId, options = {}) {
989
+ positiveId(endpointId, "endpointId");
990
+ return this.request("GET", `/org/webhooks/${endpointId}/deliveries/latest`, options);
991
+ }
992
+ async listRecentWebhookDeliveries(query = {}, options = {}) {
993
+ if (query.page !== void 0) positiveId(query.page, "page");
994
+ if (query.pageSize !== void 0) boundedInteger(query.pageSize, "pageSize", 1, 100);
995
+ if (query.endpointId !== void 0) positiveId(query.endpointId, "endpointId");
996
+ if (query.status !== void 0) nonEmpty(query.status, "status");
997
+ const path = "/org/webhooks/deliveries/recent" + queryString({
998
+ page: query.page,
999
+ page_size: query.pageSize,
1000
+ endpoint_id: query.endpointId,
1001
+ status_filter: query.status
1002
+ });
1003
+ return this.request("GET", path, options);
1004
+ }
1005
+ async getWebhookDelivery(deliveryId, options = {}) {
1006
+ positiveId(deliveryId, "deliveryId");
1007
+ return this.request("GET", `/org/webhooks/deliveries/${deliveryId}`, options);
1008
+ }
1009
+ async retryWebhookDelivery(deliveryId, options = {}) {
1010
+ positiveId(deliveryId, "deliveryId");
1011
+ return this.request("POST", `/org/webhooks/deliveries/${deliveryId}/retry`, options);
1012
+ }
1013
+ async createExport(request, options = {}) {
1014
+ const format = request.format ?? "csv";
1015
+ const scope = request.scope ?? "filtered";
1016
+ if (format !== "csv" && format !== "jsonl") throw new ValidationError("format must be 'csv' or 'jsonl'");
1017
+ if (scope !== "filtered" && scope !== "all" && scope !== "date_range") {
1018
+ throw new ValidationError("scope must be 'filtered', 'all', or 'date_range'");
1019
+ }
1020
+ const body = { format, scope };
1021
+ if (request.filters !== void 0) body.filters = request.filters === null ? null : exportFilters(request.filters);
1022
+ return this.request("POST", "/exports", { ...options, body });
1023
+ }
1024
+ async listExports(query = {}, options = {}) {
1025
+ if (query.limit !== void 0) boundedInteger(query.limit, "limit", 1, 100);
1026
+ return this.request("GET", "/exports" + queryString({ limit: query.limit }), options);
1027
+ }
1028
+ async getExport(jobId, options = {}) {
1029
+ return this.request("GET", `/exports/${pathId(jobId, "jobId", 8, 64)}`, options);
1030
+ }
1031
+ async cancelExport(jobId, options = {}) {
1032
+ return this.request("POST", `/exports/${pathId(jobId, "jobId", 8, 64)}/cancel`, options);
1033
+ }
1034
+ async retryExport(jobId, options = {}) {
1035
+ return this.request("POST", `/exports/${pathId(jobId, "jobId", 8, 64)}/retry`, options);
1036
+ }
1037
+ async getExportDownloadUrl(jobId, options = {}) {
1038
+ return this.request("GET", `/exports/${pathId(jobId, "jobId", 8, 64)}/download-url`, options);
1039
+ }
958
1040
  };
959
1041
 
960
1042
  // src/index.ts
961
- var SDK_VERSION2 = "1.4.0";
1043
+ var SDK_VERSION2 = "1.5.0";
962
1044
  function camelToSnakeKey(key) {
963
1045
  return key.replace(/([A-Z])/g, "_$1").toLowerCase();
964
1046
  }