@membranehq/sdk 0.17.1 → 0.17.2

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.
@@ -8,11 +8,32 @@ var deepEqual = require('fast-deep-equal');
8
8
  var structuredClonePolyfill = require('@ungap/structured-clone');
9
9
  var urljoin = require('url-join');
10
10
  var v4 = require('zod-validation-error/v4');
11
+ var diff = require('diff');
12
+ var yaml = require('js-yaml');
11
13
  var qs = require('qs');
12
14
  var penpal = require('penpal');
13
15
  var axiosOriginal = require('axios');
14
16
  var zodValidationError = require('zod-validation-error');
15
17
 
18
+ function _interopNamespaceDefault(e) {
19
+ var n = Object.create(null);
20
+ if (e) {
21
+ Object.keys(e).forEach(function (k) {
22
+ if (k !== 'default') {
23
+ var d = Object.getOwnPropertyDescriptor(e, k);
24
+ Object.defineProperty(n, k, d.get ? d : {
25
+ enumerable: true,
26
+ get: function () { return e[k]; }
27
+ });
28
+ }
29
+ });
30
+ }
31
+ n.default = e;
32
+ return Object.freeze(n);
33
+ }
34
+
35
+ var yaml__namespace = /*#__PURE__*/_interopNamespaceDefault(yaml);
36
+
16
37
  exports.ErrorType = void 0;
17
38
  (function (ErrorType) {
18
39
  ErrorType["BAD_REQUEST"] = "bad_request";
@@ -3471,6 +3492,7 @@ exports.WorkspaceElementType = void 0;
3471
3492
  WorkspaceElementType["ExternalEventPull"] = "external-event-pull";
3472
3493
  WorkspaceElementType["Screen"] = "screen";
3473
3494
  WorkspaceElementType["ActionRunLogRecord"] = "action-run-log-record";
3495
+ WorkspaceElementType["ConnectedProduct"] = "connected-product";
3474
3496
  })(exports.WorkspaceElementType || (exports.WorkspaceElementType = {}));
3475
3497
  exports.WorkspaceEventType = void 0;
3476
3498
  (function (WorkspaceEventType) {
@@ -3938,6 +3960,7 @@ const CreateConnectionRequestPayload = z.z.object({
3938
3960
  name: z.z.string().optional(),
3939
3961
  allowMultipleConnections: z.z.boolean().optional(),
3940
3962
  connectorParameters: z.z.record(z.z.string(), z.z.unknown()).optional(),
3963
+ redirectUri: z.z.string().url().optional(),
3941
3964
  });
3942
3965
  const ConnectionRequest = z.z.object({
3943
3966
  requestId: z.z.string(),
@@ -3950,6 +3973,7 @@ const ConnectionRequest = z.z.object({
3950
3973
  name: z.z.string().optional(),
3951
3974
  allowMultipleConnections: z.z.boolean().optional(),
3952
3975
  connectorParameters: z.z.record(z.z.string(), z.z.unknown()).optional(),
3976
+ redirectUri: z.z.string().url().optional(),
3953
3977
  status: z.z.enum(['pending', 'success', 'cancelled', 'error']),
3954
3978
  resultConnectionId: z.z.string().optional(),
3955
3979
  resultError: ErrorDataSchema.optional(),
@@ -10118,6 +10142,26 @@ const BaseActionRunLogRecord = ActivityLogRecord.extend({
10118
10142
  meta: z.z.record(z.z.string(), z.z.any()).optional(),
10119
10143
  });
10120
10144
 
10145
+ const ConnectedProductType = z.z.enum(['ai-agent', 'app']);
10146
+ const ConnectedProductAudience = z.z.enum(['personal', 'customers']);
10147
+ const AiAgentAudience = ConnectedProductAudience;
10148
+ const AiAgentType = z.z.enum(['openclaw', 'claude', 'chatgpt', 'custom']);
10149
+ const AiAgentParameters = z.z.object({
10150
+ agentType: AiAgentType.optional(),
10151
+ });
10152
+ const BaseConnectedProduct = z.z.object({
10153
+ id: z.z.string(),
10154
+ name: z.z.string(),
10155
+ key: z.z.string(),
10156
+ type: ConnectedProductType,
10157
+ audience: ConnectedProductAudience.optional(),
10158
+ parameters: AiAgentParameters.optional(),
10159
+ isConnected: z.z.boolean().optional(),
10160
+ lastApiRequestDate: z.z.string().optional(),
10161
+ createdAt: z.z.string().optional(),
10162
+ archivedAt: z.z.string().optional(),
10163
+ });
10164
+
10121
10165
  const ActionApiResponse = BaseAction.extend({
10122
10166
  integration: BaseIntegration.optional(),
10123
10167
  user: BaseCustomer.optional(),
@@ -11241,6 +11285,29 @@ const IncomingWebhookApiResponse = z.z.object({
11241
11285
  subscription: BaseExternalEventSubscription.optional(),
11242
11286
  });
11243
11287
 
11288
+ const CreateConnectedProductRequest = z.z.object({
11289
+ name: z.z.string(),
11290
+ type: ConnectedProductType,
11291
+ audience: ConnectedProductAudience.optional(),
11292
+ parameters: AiAgentParameters.optional(),
11293
+ });
11294
+ const UpdateConnectedProductRequest = z.z.object({
11295
+ name: z.z.string().optional(),
11296
+ type: ConnectedProductType.optional(),
11297
+ audience: ConnectedProductAudience.optional(),
11298
+ parameters: AiAgentParameters.optional(),
11299
+ });
11300
+ const FindConnectedProductsQuery = z.z
11301
+ .object({
11302
+ type: ConnectedProductType.optional(),
11303
+ audience: ConnectedProductAudience.optional(),
11304
+ key: z.z.string().optional(),
11305
+ })
11306
+ .merge(PaginationQuery)
11307
+ .merge(SearchQuery)
11308
+ .merge(IncludeArchivedQuery);
11309
+ const ConnectedProductApiResponse = BaseConnectedProduct;
11310
+
11244
11311
  class DependencyError extends MembraneError {
11245
11312
  constructor(arg, workspaceElementReference) {
11246
11313
  super(arg);
@@ -11836,6 +11903,13 @@ const WorkspaceElementSpecs = {
11836
11903
  hasKey: true,
11837
11904
  isProOnly: true,
11838
11905
  },
11906
+ [exports.WorkspaceElementType.ConnectedProduct]: {
11907
+ type: exports.WorkspaceElementType.ConnectedProduct,
11908
+ apiPath: 'connected-products',
11909
+ name: 'Connected Product',
11910
+ namePlural: 'Connected Products',
11911
+ hasKey: true,
11912
+ },
11839
11913
  };
11840
11914
  function getEditablePathsForElementType(elementType) {
11841
11915
  return getEditablePathsForElementType$1(WorkspaceElementSpecs, elementType);
@@ -12812,13 +12886,14 @@ exports.WorkspaceElementChangeType = void 0;
12812
12886
  WorkspaceElementChangeType["DELETE"] = "delete";
12813
12887
  })(exports.WorkspaceElementChangeType || (exports.WorkspaceElementChangeType = {}));
12814
12888
  function compareWorkspaceExports(baseExport, targetExport, options = { includeDeletions: true }) {
12815
- const changes = [];
12889
+ const changes = {};
12816
12890
  const comparison = {
12817
12891
  [exports.WorkspaceElementChangeType.CREATE]: new Set(),
12818
12892
  [exports.WorkspaceElementChangeType.UPDATE]: new Set(),
12819
12893
  [exports.WorkspaceElementChangeType.DELETE]: new Set(),
12820
12894
  };
12821
12895
  const sourceUuidByTargetUuid = new Map();
12896
+ const diffs = [];
12822
12897
  const integrationMap = buildIntegrationsMap([
12823
12898
  ...(baseExport[exports.WorkspaceElementType.Integration] || []),
12824
12899
  ...(targetExport[exports.WorkspaceElementType.Integration] || []),
@@ -12833,35 +12908,46 @@ function compareWorkspaceExports(baseExport, targetExport, options = { includeDe
12833
12908
  for (const element of baseElements) {
12834
12909
  const intIdentifier = getIntegrationIdentifier(element, integrationMap);
12835
12910
  const selector = getElementSelector(type, element.key, intIdentifier);
12836
- baseMap.set(selector, element);
12911
+ baseMap.set(selector, { type, element });
12837
12912
  allSelectors.add(selector);
12838
12913
  }
12839
12914
  const targetElements = targetExport[type] || [];
12840
12915
  for (const element of targetElements) {
12841
12916
  const intIdentifier = getIntegrationIdentifier(element, integrationMap);
12842
12917
  const selector = getElementSelector(type, element.key, intIdentifier);
12843
- targetMap.set(selector, element);
12918
+ targetMap.set(selector, { type, element });
12844
12919
  allSelectors.add(selector);
12845
12920
  }
12846
12921
  }
12847
12922
  for (const selector of allSelectors) {
12848
- const baseElement = baseMap.get(selector);
12849
- const targetElement = targetMap.get(selector);
12850
- if (baseElement && targetElement && baseElement.uuid !== targetElement.uuid) {
12851
- sourceUuidByTargetUuid.set(targetElement.uuid, baseElement.uuid);
12923
+ const base = baseMap.get(selector);
12924
+ const target = targetMap.get(selector);
12925
+ if (base && target && base.element.uuid !== target.element.uuid) {
12926
+ sourceUuidByTargetUuid.set(target.element.uuid, base.element.uuid);
12852
12927
  }
12853
- const change = compareElementExports(baseElement, targetElement);
12928
+ const change = compareElementExports(base === null || base === void 0 ? void 0 : base.element, target === null || target === void 0 ? void 0 : target.element);
12854
12929
  if (options.includeDeletions === false && (change === null || change === void 0 ? void 0 : change.type) === exports.WorkspaceElementChangeType.DELETE) {
12855
12930
  continue;
12856
12931
  }
12857
- if (change) {
12858
- changes.push(change);
12932
+ if (!change) {
12933
+ continue;
12859
12934
  }
12860
- }
12861
- changes.forEach((change) => {
12935
+ const subject = target || base;
12936
+ const integrationKey = getIntegrationIdentifier(subject.element, integrationMap);
12937
+ const path = getMembraneElementPath(subject.type, subject.element.key, integrationKey);
12938
+ changes[change.uuid] = { elementType: subject.type, path };
12862
12939
  comparison[change.type].add(change.uuid);
12863
- });
12864
- return { comparison, sourceUuidByTargetUuid };
12940
+ if (options.includeDiff) {
12941
+ const baseYaml = base ? yaml__namespace.dump(base.element) : '';
12942
+ const targetYaml = target ? yaml__namespace.dump(target.element) : '';
12943
+ diffs.push(diff.createTwoFilesPatch(`a/${path}`, `b/${path}`, baseYaml, targetYaml));
12944
+ }
12945
+ }
12946
+ const result = { comparison, changes, sourceUuidByTargetUuid };
12947
+ if (options.includeDiff) {
12948
+ result.diff = diffs.join('\n').trim();
12949
+ }
12950
+ return result;
12865
12951
  }
12866
12952
  function compareElementExports(baseElement, targetElement) {
12867
12953
  if (baseElement && !targetElement) {
@@ -14493,6 +14579,7 @@ async function createOrUpdateConnection(options) {
14493
14579
  const { stopSSE } = createSSEListener({
14494
14580
  apiUri: apiUri,
14495
14581
  requestId,
14582
+ token,
14496
14583
  handler: eventHandler,
14497
14584
  });
14498
14585
  function cleanup() {
@@ -14607,8 +14694,8 @@ const createCrossWindowListener = ({ handler }) => {
14607
14694
  },
14608
14695
  };
14609
14696
  };
14610
- const createSSEListener = ({ apiUri, requestId, handler, }) => {
14611
- const sseUrl = urljoin(apiUri, '/sse/connection-events', requestId);
14697
+ const createSSEListener = ({ apiUri, requestId, token, handler, }) => {
14698
+ const sseUrl = urljoin(apiUri, '/sse/connection-events', requestId) + `?token=${encodeURIComponent(token)}`;
14612
14699
  let eventSource = null;
14613
14700
  const closeSseConnection = () => {
14614
14701
  eventSource === null || eventSource === void 0 ? void 0 : eventSource.close();
@@ -15144,7 +15231,9 @@ const AgentSession = z.z.object({
15144
15231
  status: z.z.enum(exports.AgentSessionStatus),
15145
15232
  prompt: z.z.string(),
15146
15233
  error: ErrorDataSchema.optional(),
15147
- lastActivityAt: z.z.iso.datetime(),
15234
+ lastActivityAt: z.z.iso
15235
+ .datetime()
15236
+ .describe('Last meaningful session progress timestamp used for inactivity timeout checks.'),
15148
15237
  title: z.z.string().optional(),
15149
15238
  summary: z.z.string().optional(),
15150
15239
  cost: z.z.number().optional(),
@@ -15171,7 +15260,10 @@ const AgentSessionInputSchema = z.z.object({
15171
15260
  });
15172
15261
  const PatchAgentSessionSchema = z.z.object({
15173
15262
  state: z.z.enum(exports.AgentSessionState).optional(),
15174
- lastActivityAt: z.z.iso.datetime().optional(),
15263
+ lastActivityAt: z.z.iso
15264
+ .datetime()
15265
+ .optional()
15266
+ .describe('Last meaningful session progress timestamp used for inactivity timeout checks.'),
15175
15267
  title: z.z.string().optional(),
15176
15268
  summary: z.z.string().optional(),
15177
15269
  cost: z.z.number().optional(),
@@ -15248,14 +15340,18 @@ const ClientToken = z.z.object({
15248
15340
  grantType: ClientTokenGrantType,
15249
15341
  grantId: z.z.string().optional(),
15250
15342
  grantName: z.z.string().optional(),
15251
- accessToken: z.z.string().optional(),
15343
+ connectedProductId: z.z.string().optional(),
15252
15344
  createdAt: z.z.string(),
15253
15345
  });
15346
+ const CreateClientTokenResponse = ClientToken.extend({
15347
+ accessToken: z.z.string(),
15348
+ });
15254
15349
  const CreateClientTokenRequest = z.z.object({
15255
15350
  grantType: ClientTokenGrantType,
15256
15351
  grantId: z.z.string(),
15257
15352
  grantName: z.z.string(),
15258
15353
  tenantId: z.z.string().optional(),
15354
+ productKey: z.z.string().optional(),
15259
15355
  });
15260
15356
  const ClientTokenListResponse = z.z.object({
15261
15357
  items: z.z.array(ClientToken),
@@ -15270,8 +15366,8 @@ const OAuthTokenResponse = z.z.object({
15270
15366
  token_type: z.z.string(),
15271
15367
  expires_in: z.z.number(),
15272
15368
  refresh_token: z.z.string().optional(),
15273
- default_workspace_id: z.z.string().optional(),
15274
- default_tenant_id: z.z.string().optional(),
15369
+ default_workspace_key: z.z.string().optional(),
15370
+ default_tenant_key: z.z.string().optional(),
15275
15371
  });
15276
15372
 
15277
15373
  const CONSOLE_ACCOUNT_API_TOKEN_PATH = 'settings/account/api-token';
@@ -15733,6 +15829,9 @@ exports.ActivityLogRecord = ActivityLogRecord;
15733
15829
  exports.ActivityStatsQuery = ActivityStatsQuery;
15734
15830
  exports.AgentSession = AgentSession;
15735
15831
  exports.AgentSessionInputSchema = AgentSessionInputSchema;
15832
+ exports.AiAgentAudience = AiAgentAudience;
15833
+ exports.AiAgentParameters = AiAgentParameters;
15834
+ exports.AiAgentType = AiAgentType;
15736
15835
  exports.Alert = Alert;
15737
15836
  exports.AlertDeliverySettingsSchema = AlertDeliverySettingsSchema;
15738
15837
  exports.AlertSchema = AlertSchema;
@@ -15768,6 +15867,7 @@ exports.BaseAppDataSchema = BaseAppDataSchema;
15768
15867
  exports.BaseAppDataSchemaInstance = BaseAppDataSchemaInstance;
15769
15868
  exports.BaseAppEventSubscription = BaseAppEventSubscription;
15770
15869
  exports.BaseAppEventType = BaseAppEventType;
15870
+ exports.BaseConnectedProduct = BaseConnectedProduct;
15771
15871
  exports.BaseConnection = BaseConnection;
15772
15872
  exports.BaseConnector = BaseConnector;
15773
15873
  exports.BaseCustomer = BaseCustomer;
@@ -15826,6 +15926,9 @@ exports.ConcurrencyError = ConcurrencyError;
15826
15926
  exports.ConfigurationError = ConfigurationError;
15827
15927
  exports.ConnectPayload = ConnectPayload;
15828
15928
  exports.ConnectUIOptions = ConnectUIOptions;
15929
+ exports.ConnectedProductApiResponse = ConnectedProductApiResponse;
15930
+ exports.ConnectedProductAudience = ConnectedProductAudience;
15931
+ exports.ConnectedProductType = ConnectedProductType;
15829
15932
  exports.ConnectionAccessor = ConnectionAccessor;
15830
15933
  exports.ConnectionApiResponse = ConnectionApiResponse;
15831
15934
  exports.ConnectionApiResponseWithSecrets = ConnectionApiResponseWithSecrets;
@@ -15895,6 +15998,8 @@ exports.CreateActionRequest = CreateActionRequest;
15895
15998
  exports.CreateAgentSession = CreateAgentSession;
15896
15999
  exports.CreateAlert = CreateAlert;
15897
16000
  exports.CreateClientTokenRequest = CreateClientTokenRequest;
16001
+ exports.CreateClientTokenResponse = CreateClientTokenResponse;
16002
+ exports.CreateConnectedProductRequest = CreateConnectedProductRequest;
15898
16003
  exports.CreateConnectionRequest = CreateConnectionRequest;
15899
16004
  exports.CreateConnectionRequestPayload = CreateConnectionRequestPayload;
15900
16005
  exports.CreateConnectorRequest = CreateConnectorRequest;
@@ -16028,6 +16133,7 @@ exports.FindAppDataSchemasQuery = FindAppDataSchemasQuery;
16028
16133
  exports.FindAppEventSubscriptionsQuery = FindAppEventSubscriptionsQuery;
16029
16134
  exports.FindAppEventTypesQuery = FindAppEventTypesQuery;
16030
16135
  exports.FindAppEventsQuery = FindAppEventsQuery;
16136
+ exports.FindConnectedProductsQuery = FindConnectedProductsQuery;
16031
16137
  exports.FindConnectionsQuery = FindConnectionsQuery;
16032
16138
  exports.FindConnectionsResponse = FindConnectionsResponse;
16033
16139
  exports.FindCustomersQuery = FindCustomersQuery;
@@ -16214,6 +16320,7 @@ exports.UNIFIED_DATA_MODELS = UNIFIED_DATA_MODELS;
16214
16320
  exports.UnitRunError = UnitRunError;
16215
16321
  exports.UpdateActionInstanceRequest = UpdateActionInstanceRequest;
16216
16322
  exports.UpdateActionRequest = UpdateActionRequest;
16323
+ exports.UpdateConnectedProductRequest = UpdateConnectedProductRequest;
16217
16324
  exports.UpdateConnectionRequest = UpdateConnectionRequest;
16218
16325
  exports.UpdateConnectorRequest = UpdateConnectorRequest;
16219
16326
  exports.UpdateCustomerRequest = UpdateCustomerRequest;