memorysync-sdk 1.0.2 → 1.1.1

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/README.md CHANGED
@@ -70,6 +70,56 @@ if ("status" in result && result.status === "skipped") {
70
70
  }
71
71
  ```
72
72
 
73
+ ## Control-plane client
74
+
75
+ `ControlPlaneClient` is a separate bearer-authenticated client for trusted dashboard and administrative flows. It never sends an API key, persists login tokens, or refreshes tokens automatically. `login()` is the only method that does not require `accessToken`.
76
+
77
+ ```ts
78
+ import { ControlPlaneClient } from "memorysync-sdk";
79
+
80
+ const control = new ControlPlaneClient({
81
+ baseUrl: "https://api.memorysync.io",
82
+ accessToken: process.env.MEMORYSYNC_ACCESS_TOKEN,
83
+ projectId: "project_abc123", // optional X-Project-ID default
84
+ });
85
+
86
+ const plan = await control.getCurrentPlan();
87
+ const hooks = await control.listWebhooks({ projectId: "project_override" });
88
+
89
+ // This returns tokens but does not store them on the client.
90
+ const login = await new ControlPlaneClient({
91
+ baseUrl: "https://api.memorysync.io",
92
+ }).login({ email: "developer@example.com", password: "..." });
93
+ ```
94
+
95
+ Control-plane configuration accepts `baseUrl`, optional `accessToken`, optional `projectId`, optional `timeoutMs`, and optional injectable `fetch`. Every call accepts a final `{ projectId? }` override. Public request and response fields are camelCase; the client explicitly encodes documented snake_case wire fields and normalizes response objects.
96
+
97
+ | Method | Route |
98
+ | --- | --- |
99
+ | `bulkRevokeApiKeys(req, options?)` | `POST /org/api-keys/bulk-revoke` |
100
+ | `testApiKey(keyId, options?)` | `POST /org/api-keys/{key_id}/test` |
101
+ | `login(req, options?)` | `POST /auth/login` |
102
+ | `getCurrentPlan(options?)` | `GET /org/billing/current-plan` |
103
+ | `listTeamMembers(options?)` | `GET /admin/team/members` |
104
+ | `suspendTeamMember(memberId, options?)` | `PATCH /admin/team/members/{member_id}` |
105
+ | `removeTeamMember(memberId, options?)` | `DELETE /admin/team/members/{member_id}` |
106
+ | `listSessions(options?)` | `GET /auth/sessions` |
107
+ | `revokeSession(sessionId, options?)` | `POST /auth/sessions/{session_id}/revoke` |
108
+ | `listAuditEvents(query?, options?)` | `GET /admin/audit-logs` |
109
+ | `listIntegrations(query?, options?)` | `GET /api/v1/integrations/catalog` |
110
+ | `createOrganization(req, options?)` | `POST /organizations` |
111
+ | `listOrganizations(options?)` | `GET /organizations` |
112
+ | `listOrganizationMembers(options?)` | delegates to `listTeamMembers` |
113
+ | `getOrganizationSettings(query?, options?)` | `GET /admin/tenant-settings` |
114
+ | `listProjects(options?)` | `GET /org/projects` |
115
+ | `createWebhook(req, options?)` | `POST /org/webhooks` |
116
+ | `listWebhooks(options?)` | `GET /org/webhooks` |
117
+ | `updateWebhook(endpointId, req, options?)` | `PATCH /org/webhooks/{endpoint_id}` |
118
+ | `deleteWebhook(endpointId, options?)` | `DELETE /org/webhooks/{endpoint_id}` |
119
+ | `testWebhook(endpointId, req?, options?)` | `POST /org/webhooks/{endpoint_id}/test` |
120
+ | `replayWebhookDeliveries(endpointId, req?, options?)` | `POST /org/webhooks/{endpoint_id}/replay` |
121
+ | `listWebhookDeliveries(endpointId, query?, options?)` | `GET /org/webhooks/{endpoint_id}/deliveries` |
122
+
73
123
  ## Errors
74
124
 
75
125
  Every non-2xx response throws a typed subclass of `MemorySyncError`:
package/dist/index.d.mts CHANGED
@@ -1,3 +1,415 @@
1
+ interface ErrorOptions {
2
+ statusCode?: number;
3
+ response?: unknown;
4
+ requestId?: string;
5
+ }
6
+ declare class MemorySyncError extends Error {
7
+ readonly statusCode?: number;
8
+ readonly response?: unknown;
9
+ readonly requestId?: string;
10
+ constructor(message: string, options?: ErrorOptions);
11
+ }
12
+ declare class AuthError extends MemorySyncError {
13
+ constructor(message: string, options?: ErrorOptions);
14
+ }
15
+ declare class ValidationError extends MemorySyncError {
16
+ constructor(message: string, options?: ErrorOptions);
17
+ }
18
+ declare class NotFoundError extends MemorySyncError {
19
+ constructor(message: string, options?: ErrorOptions);
20
+ }
21
+ declare class RateLimitError extends MemorySyncError {
22
+ readonly retryAfterSeconds: number;
23
+ constructor(message: string, retryAfterSeconds: number, options?: ErrorOptions);
24
+ }
25
+ declare class ServerError extends MemorySyncError {
26
+ constructor(message: string, options?: ErrorOptions);
27
+ }
28
+
29
+ interface ControlPlaneConfig {
30
+ baseUrl: string;
31
+ accessToken?: string;
32
+ projectId?: string;
33
+ timeoutMs?: number;
34
+ fetch?: typeof fetch;
35
+ }
36
+ interface ControlPlaneRequestOptions {
37
+ projectId?: string;
38
+ }
39
+ interface LoginRequest {
40
+ email: string;
41
+ password: string;
42
+ }
43
+ interface LoginResponse {
44
+ tokens: {
45
+ accessToken: string;
46
+ refreshToken: string;
47
+ tokenType: string;
48
+ };
49
+ session: {
50
+ userId: number;
51
+ organizationId: number;
52
+ role: string;
53
+ };
54
+ mfaRequired: boolean;
55
+ mfaSetupRequired: boolean;
56
+ }
57
+ type ApiKeyTestStatus = "active" | "revoked" | "expired" | string;
58
+ interface BulkRevokeApiKeysRequest {
59
+ keyIds: number[];
60
+ }
61
+ interface BulkRevokeApiKeyResult {
62
+ keyId: number;
63
+ status: "revoked" | "already_revoked" | "not_found" | "forbidden";
64
+ }
65
+ interface BulkRevokeApiKeysResponse {
66
+ revoked: number;
67
+ alreadyRevoked: number;
68
+ notFound: number;
69
+ results: BulkRevokeApiKeyResult[];
70
+ }
71
+ interface ApiKeyTestResponse {
72
+ keyId: number;
73
+ valid: boolean;
74
+ status: ApiKeyTestStatus;
75
+ environment: string;
76
+ rateLimitTier: string;
77
+ scopes: string[];
78
+ projectId: string | null;
79
+ lastUsedAt: string | null;
80
+ expiresAt: string | null;
81
+ expired: boolean;
82
+ serverTime: string;
83
+ }
84
+ interface PlanLimits {
85
+ addRequests: number | null;
86
+ retrievalRequests: number | null;
87
+ }
88
+ interface Plan {
89
+ id: string;
90
+ name: string;
91
+ priceCents?: number | null;
92
+ priceLabel: string;
93
+ description?: string;
94
+ limits: PlanLimits;
95
+ features?: string[];
96
+ ctaLabel?: string;
97
+ isEnterprise?: boolean;
98
+ }
99
+ interface CurrentPlanResponse {
100
+ plan: Plan;
101
+ status: string;
102
+ billingPeriodStart: string | null;
103
+ billingPeriodEnd: string | null;
104
+ nextResetAt?: string | null;
105
+ planLimitAdd?: number | null;
106
+ planLimitRetrieval?: number | null;
107
+ paymentFailed: boolean;
108
+ paymentStatus?: string;
109
+ scheduledPlanId: string | null;
110
+ cancelAtPeriodEnd: boolean;
111
+ }
112
+ interface TeamMember {
113
+ id: string;
114
+ name: string;
115
+ email: string;
116
+ role: string;
117
+ status: string;
118
+ lastActive?: string | null;
119
+ mfaEnabled: boolean;
120
+ authMethod: string;
121
+ loginProvider?: string;
122
+ devices?: number;
123
+ sessions: number;
124
+ isScimManaged?: boolean;
125
+ }
126
+ interface Session {
127
+ id: number;
128
+ isCurrent: boolean;
129
+ sessionType: string;
130
+ sessionName: string;
131
+ userAgent: string;
132
+ ip: string;
133
+ location: string | null;
134
+ geo: Record<string, unknown> | null;
135
+ createdAt: string;
136
+ lastActivityAt: string;
137
+ expiresAt: string;
138
+ }
139
+ interface SessionListResponse {
140
+ sessions: Session[];
141
+ currentSessionId: number | null;
142
+ }
143
+ type AuditSortDirection = "asc" | "desc";
144
+ interface AuditEventQuery {
145
+ limit?: number;
146
+ cursor?: number;
147
+ skip?: number;
148
+ sortDirection?: AuditSortDirection;
149
+ tenantId?: string;
150
+ actor?: string;
151
+ actorEmail?: string;
152
+ ip?: string;
153
+ action?: string;
154
+ resourceType?: string;
155
+ resourceId?: string;
156
+ severity?: string;
157
+ category?: string;
158
+ start?: string;
159
+ end?: string;
160
+ success?: boolean;
161
+ source?: string;
162
+ ingestMethod?: string;
163
+ search?: string;
164
+ includeStats?: boolean;
165
+ }
166
+ interface AuditActor {
167
+ id: string;
168
+ email: string | null;
169
+ name: string | null;
170
+ type: string;
171
+ }
172
+ interface AuditResource {
173
+ type: string;
174
+ id: string;
175
+ label: string | null;
176
+ }
177
+ interface AuditEvent {
178
+ id: number;
179
+ eventId: string;
180
+ timestamp: string;
181
+ category: string;
182
+ actor: AuditActor;
183
+ action: string;
184
+ resource: AuditResource;
185
+ severity: string;
186
+ success: boolean;
187
+ metadata?: Record<string, unknown> | null;
188
+ }
189
+ interface AuditEventListResponse {
190
+ events: AuditEvent[];
191
+ nextCursor: number | null;
192
+ stats?: Record<string, unknown> | null;
193
+ sort: AuditSortDirection;
194
+ }
195
+ interface IntegrationQuery {
196
+ category?: string;
197
+ }
198
+ interface Integration {
199
+ id: string;
200
+ name: string;
201
+ description: string;
202
+ category: string;
203
+ features: string[];
204
+ authType: string;
205
+ isConfigured: boolean;
206
+ isConnected: boolean;
207
+ comingSoon: boolean;
208
+ }
209
+ interface CreateOrganizationRequest {
210
+ name: string;
211
+ domain?: string;
212
+ }
213
+ interface OrganizationMembership {
214
+ userId: number;
215
+ organizationId: number;
216
+ role: string;
217
+ }
218
+ interface OrganizationSettingsQuery {
219
+ tenantId?: string;
220
+ }
221
+ interface OrganizationSettings {
222
+ tenantId: string;
223
+ tenantName: string;
224
+ tenantSlug: string;
225
+ description: string | null;
226
+ plan: string;
227
+ status: string;
228
+ createdAt: string;
229
+ contactEmail: string | null;
230
+ customDomain: string | null;
231
+ customDomainVerified: boolean;
232
+ logoUrl: string | null;
233
+ totalMemories: number;
234
+ activeUsers: number;
235
+ organizationName: string;
236
+ scheduledDeletionAt: string | null;
237
+ mfaEnrolled: boolean;
238
+ passwordEnabled: boolean;
239
+ }
240
+ interface Project {
241
+ id: string;
242
+ name: string;
243
+ tenantId: string;
244
+ isDefault: boolean;
245
+ memoryCount: number;
246
+ archivedAt: string | null;
247
+ createdAt: string;
248
+ updatedAt: string;
249
+ }
250
+ interface WebhookRetryConfig {
251
+ enabled?: boolean;
252
+ maxRetries?: number;
253
+ initialDelaySeconds?: number;
254
+ maxDelaySeconds?: number;
255
+ backoffMultiplier?: number;
256
+ retryStatusCodes?: string[];
257
+ }
258
+ interface WebhookSignatureConfig {
259
+ algorithm?: "hmac-sha256" | "hmac-sha512";
260
+ headerName?: string;
261
+ timestampHeader?: string;
262
+ toleranceSeconds?: number;
263
+ }
264
+ interface CreateWebhookRequest {
265
+ name: string;
266
+ url: string;
267
+ events: string[];
268
+ description?: string;
269
+ retryConfig?: WebhookRetryConfig;
270
+ signatureConfig?: WebhookSignatureConfig;
271
+ projectId?: string;
272
+ }
273
+ interface UpdateWebhookRequest {
274
+ name?: string;
275
+ url?: string;
276
+ description?: string;
277
+ events?: string[];
278
+ retryConfig?: WebhookRetryConfig;
279
+ signatureConfig?: WebhookSignatureConfig;
280
+ }
281
+ interface Webhook {
282
+ id: number;
283
+ name: string;
284
+ url: string;
285
+ description: string | null;
286
+ secretPrefix: string;
287
+ events: string[];
288
+ enabled: boolean;
289
+ signatureAlgorithm: string;
290
+ signatureHeader?: string;
291
+ timestampHeader?: string;
292
+ signatureTolerance?: number;
293
+ retryEnabled?: boolean;
294
+ maxRetries?: number;
295
+ initialDelaySeconds?: number;
296
+ maxDelaySeconds?: number;
297
+ backoffMultiplier?: number;
298
+ retryStatusCodes?: string[];
299
+ totalDeliveries?: number;
300
+ successfulDeliveries?: number;
301
+ failedDeliveries?: number;
302
+ consecutiveFailures?: number;
303
+ successRate?: number;
304
+ lastTriggeredAt?: string | null;
305
+ lastSuccessAt?: string | null;
306
+ lastFailureAt?: string | null;
307
+ lastError?: string | null;
308
+ lastStatusCode?: number | null;
309
+ createdAt?: string;
310
+ updatedAt?: string;
311
+ createdByName?: string | null;
312
+ projectId: string | null;
313
+ }
314
+ interface CreatedWebhook extends Webhook {
315
+ secret: string;
316
+ }
317
+ interface WebhookListResponse {
318
+ endpoints: Webhook[];
319
+ totalEndpoints: number;
320
+ activeEndpoints: number;
321
+ totalDeliveries: number;
322
+ avgSuccessRate: number;
323
+ failingEndpoints: number;
324
+ }
325
+ interface TestWebhookRequest {
326
+ eventType?: string;
327
+ }
328
+ interface TestWebhookResponse {
329
+ deliveryId: number;
330
+ eventId: string;
331
+ eventType: string;
332
+ endpointId: number;
333
+ status: string;
334
+ payload: Record<string, unknown>;
335
+ message: string;
336
+ }
337
+ interface ReplayWebhookDeliveriesRequest {
338
+ sinceMinutes?: number;
339
+ statuses?: string[];
340
+ limit?: number;
341
+ }
342
+ interface ReplayWebhookDeliveriesResponse {
343
+ endpointId: number;
344
+ eligible: number;
345
+ replayed: number;
346
+ skipped: number;
347
+ deliveryIds: number[];
348
+ }
349
+ interface WebhookDeliveryQuery {
350
+ page?: number;
351
+ pageSize?: number;
352
+ status?: string;
353
+ }
354
+ interface WebhookDelivery {
355
+ id: number;
356
+ endpointId: number;
357
+ eventType: string;
358
+ eventId: string;
359
+ status: string;
360
+ payload?: Record<string, unknown>;
361
+ payloadHash: string;
362
+ signature?: string | null;
363
+ statusCode: number | null;
364
+ responseBody?: string | null;
365
+ errorMessage?: string | null;
366
+ latencyMs: number | null;
367
+ attemptNumber: number;
368
+ maxAttempts: number;
369
+ nextRetryAt?: string | null;
370
+ createdAt: string;
371
+ completedAt: string | null;
372
+ }
373
+ interface WebhookDeliveryListResponse {
374
+ deliveries: WebhookDelivery[];
375
+ total: number;
376
+ page: number;
377
+ pageSize: number;
378
+ }
379
+ declare class ControlPlaneClient {
380
+ private readonly baseUrl;
381
+ private readonly accessToken?;
382
+ private readonly projectId?;
383
+ private readonly timeoutMs;
384
+ private readonly fetchImpl;
385
+ constructor(config: ControlPlaneConfig);
386
+ private request;
387
+ private throwForStatus;
388
+ bulkRevokeApiKeys(request: BulkRevokeApiKeysRequest, options?: ControlPlaneRequestOptions): Promise<BulkRevokeApiKeysResponse>;
389
+ testApiKey(keyId: number, options?: ControlPlaneRequestOptions): Promise<ApiKeyTestResponse>;
390
+ login(request: LoginRequest, options?: ControlPlaneRequestOptions): Promise<LoginResponse>;
391
+ getCurrentPlan(options?: ControlPlaneRequestOptions): Promise<CurrentPlanResponse>;
392
+ listTeamMembers(options?: ControlPlaneRequestOptions): Promise<TeamMember[]>;
393
+ suspendTeamMember(memberId: number, options?: ControlPlaneRequestOptions): Promise<TeamMember>;
394
+ removeTeamMember(memberId: number, options?: ControlPlaneRequestOptions): Promise<void>;
395
+ listSessions(options?: ControlPlaneRequestOptions): Promise<SessionListResponse>;
396
+ revokeSession(sessionId: number, options?: ControlPlaneRequestOptions): Promise<void>;
397
+ listAuditEvents(query?: AuditEventQuery, options?: ControlPlaneRequestOptions): Promise<AuditEventListResponse>;
398
+ listIntegrations(query?: IntegrationQuery, options?: ControlPlaneRequestOptions): Promise<Integration[]>;
399
+ createOrganization(request: CreateOrganizationRequest, options?: ControlPlaneRequestOptions): Promise<OrganizationMembership>;
400
+ listOrganizations(options?: ControlPlaneRequestOptions): Promise<OrganizationMembership[]>;
401
+ listOrganizationMembers(options?: ControlPlaneRequestOptions): Promise<TeamMember[]>;
402
+ getOrganizationSettings(query?: OrganizationSettingsQuery, options?: ControlPlaneRequestOptions): Promise<OrganizationSettings>;
403
+ listProjects(options?: ControlPlaneRequestOptions): Promise<Project[]>;
404
+ createWebhook(request: CreateWebhookRequest, options?: ControlPlaneRequestOptions): Promise<CreatedWebhook>;
405
+ listWebhooks(options?: ControlPlaneRequestOptions): Promise<WebhookListResponse>;
406
+ updateWebhook(endpointId: number, request: UpdateWebhookRequest, options?: ControlPlaneRequestOptions): Promise<Webhook>;
407
+ deleteWebhook(endpointId: number, options?: ControlPlaneRequestOptions): Promise<void>;
408
+ testWebhook(endpointId: number, request?: TestWebhookRequest, options?: ControlPlaneRequestOptions): Promise<TestWebhookResponse>;
409
+ replayWebhookDeliveries(endpointId: number, request?: ReplayWebhookDeliveriesRequest, options?: ControlPlaneRequestOptions): Promise<ReplayWebhookDeliveriesResponse>;
410
+ listWebhookDeliveries(endpointId: number, query?: WebhookDeliveryQuery, options?: ControlPlaneRequestOptions): Promise<WebhookDeliveryListResponse>;
411
+ }
412
+
1
413
  /**
2
414
  * MemorySync SDK — JavaScript / TypeScript client.
3
415
  *
@@ -133,33 +545,7 @@ interface ExportResponse {
133
545
  memories: Array<Record<string, unknown>>;
134
546
  generatedAt: string;
135
547
  }
136
- interface ErrorOpts {
137
- statusCode?: number;
138
- response?: unknown;
139
- requestId?: string;
140
- }
141
- declare class MemorySyncError extends Error {
142
- readonly statusCode?: number;
143
- readonly response?: unknown;
144
- readonly requestId?: string;
145
- constructor(message: string, opts?: ErrorOpts);
146
- }
147
- declare class AuthError extends MemorySyncError {
148
- constructor(message: string, opts?: ErrorOpts);
149
- }
150
- declare class ValidationError extends MemorySyncError {
151
- constructor(message: string, opts?: ErrorOpts);
152
- }
153
- declare class NotFoundError extends MemorySyncError {
154
- constructor(message: string, opts?: ErrorOpts);
155
- }
156
- declare class RateLimitError extends MemorySyncError {
157
- readonly retryAfterSeconds: number;
158
- constructor(message: string, retryAfterSeconds: number, opts?: ErrorOpts);
159
- }
160
- declare class ServerError extends MemorySyncError {
161
- constructor(message: string, opts?: ErrorOpts);
162
- }
548
+
163
549
  declare class MemorySyncClient {
164
550
  private readonly apiKey;
165
551
  private readonly baseUrl;
@@ -185,4 +571,4 @@ declare class MemorySyncClient {
185
571
  createRelation(fromMemoryId: number, req: RelationCreateRequest): Promise<RelationRecord>;
186
572
  }
187
573
 
188
- export { type AddRequest, type AddResponse, type AddSkippedResponse, AuthError, type BulkAddItem, type BulkAddItemResult, type BulkAddResponse, type ComposeRequest, type ComposeResponse, type ExportResponse, type MemoryRecord, MemorySyncClient, type MemorySyncConfig, MemorySyncError, NotFoundError, type QueryFilters, type QueryRequest, type QueryResponse, RateLimitError, type RelationCreateRequest, type RelationRecord, type RelationshipType, ServerError, type SummarizeRequest, type UpdateRequest, ValidationError };
574
+ export { type AddRequest, type AddResponse, type AddSkippedResponse, type ApiKeyTestResponse, type ApiKeyTestStatus, type AuditActor, type AuditEvent, type AuditEventListResponse, type AuditEventQuery, type AuditResource, type AuditSortDirection, AuthError, type BulkAddItem, type BulkAddItemResult, type BulkAddResponse, type BulkRevokeApiKeyResult, type BulkRevokeApiKeysRequest, type BulkRevokeApiKeysResponse, type ComposeRequest, type ComposeResponse, ControlPlaneClient, type ControlPlaneConfig, type ControlPlaneRequestOptions, type CreateOrganizationRequest, type CreateWebhookRequest, type CreatedWebhook, type CurrentPlanResponse, type ExportResponse, type Integration, type IntegrationQuery, type LoginRequest, type LoginResponse, type MemoryRecord, MemorySyncClient, type MemorySyncConfig, MemorySyncError, NotFoundError, type OrganizationMembership, type OrganizationSettings, type OrganizationSettingsQuery, type Plan, type PlanLimits, type Project, type QueryFilters, type QueryRequest, type QueryResponse, RateLimitError, type RelationCreateRequest, type RelationRecord, type RelationshipType, type ReplayWebhookDeliveriesRequest, type ReplayWebhookDeliveriesResponse, ServerError, type Session, type SessionListResponse, type SummarizeRequest, type TeamMember, type TestWebhookRequest, type TestWebhookResponse, type UpdateRequest, type UpdateWebhookRequest, ValidationError, type Webhook, type WebhookDelivery, type WebhookDeliveryListResponse, type WebhookDeliveryQuery, type WebhookListResponse, type WebhookRetryConfig, type WebhookSignatureConfig };