@membranehq/sdk 0.17.1 → 0.17.3

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,13 +8,14 @@ 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
  var fs = require('fs');
16
18
  var path = require('path');
17
- var yaml = require('js-yaml');
18
19
 
19
20
  function _interopNamespaceDefault(e) {
20
21
  var n = Object.create(null);
@@ -33,9 +34,9 @@ function _interopNamespaceDefault(e) {
33
34
  return Object.freeze(n);
34
35
  }
35
36
 
37
+ var yaml__namespace = /*#__PURE__*/_interopNamespaceDefault(yaml);
36
38
  var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
37
39
  var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
38
- var yaml__namespace = /*#__PURE__*/_interopNamespaceDefault(yaml);
39
40
 
40
41
  exports.ErrorType = void 0;
41
42
  (function (ErrorType) {
@@ -3495,6 +3496,7 @@ exports.WorkspaceElementType = void 0;
3495
3496
  WorkspaceElementType["ExternalEventPull"] = "external-event-pull";
3496
3497
  WorkspaceElementType["Screen"] = "screen";
3497
3498
  WorkspaceElementType["ActionRunLogRecord"] = "action-run-log-record";
3499
+ WorkspaceElementType["ConnectedProduct"] = "connected-product";
3498
3500
  })(exports.WorkspaceElementType || (exports.WorkspaceElementType = {}));
3499
3501
  exports.WorkspaceEventType = void 0;
3500
3502
  (function (WorkspaceEventType) {
@@ -3962,6 +3964,7 @@ const CreateConnectionRequestPayload = z.z.object({
3962
3964
  name: z.z.string().optional(),
3963
3965
  allowMultipleConnections: z.z.boolean().optional(),
3964
3966
  connectorParameters: z.z.record(z.z.string(), z.z.unknown()).optional(),
3967
+ redirectUri: z.z.string().url().optional(),
3965
3968
  });
3966
3969
  const ConnectionRequest = z.z.object({
3967
3970
  requestId: z.z.string(),
@@ -3974,6 +3977,7 @@ const ConnectionRequest = z.z.object({
3974
3977
  name: z.z.string().optional(),
3975
3978
  allowMultipleConnections: z.z.boolean().optional(),
3976
3979
  connectorParameters: z.z.record(z.z.string(), z.z.unknown()).optional(),
3980
+ redirectUri: z.z.string().url().optional(),
3977
3981
  status: z.z.enum(['pending', 'success', 'cancelled', 'error']),
3978
3982
  resultConnectionId: z.z.string().optional(),
3979
3983
  resultError: ErrorDataSchema.optional(),
@@ -10142,6 +10146,26 @@ const BaseActionRunLogRecord = ActivityLogRecord.extend({
10142
10146
  meta: z.z.record(z.z.string(), z.z.any()).optional(),
10143
10147
  });
10144
10148
 
10149
+ const ConnectedProductType = z.z.enum(['ai-agent', 'app']);
10150
+ const ConnectedProductAudience = z.z.enum(['personal', 'customers']);
10151
+ const AiAgentAudience = ConnectedProductAudience;
10152
+ const AiAgentType = z.z.enum(['openclaw', 'claude', 'chatgpt', 'custom']);
10153
+ const AiAgentParameters = z.z.object({
10154
+ agentType: AiAgentType.optional(),
10155
+ });
10156
+ const BaseConnectedProduct = z.z.object({
10157
+ id: z.z.string(),
10158
+ name: z.z.string(),
10159
+ key: z.z.string(),
10160
+ type: ConnectedProductType,
10161
+ audience: ConnectedProductAudience.optional(),
10162
+ parameters: AiAgentParameters.optional(),
10163
+ isConnected: z.z.boolean().optional(),
10164
+ lastApiRequestDate: z.z.string().optional(),
10165
+ createdAt: z.z.string().optional(),
10166
+ archivedAt: z.z.string().optional(),
10167
+ });
10168
+
10145
10169
  const ActionApiResponse = BaseAction.extend({
10146
10170
  integration: BaseIntegration.optional(),
10147
10171
  user: BaseCustomer.optional(),
@@ -10717,6 +10741,9 @@ const FindCustomersQuery = z.z
10717
10741
  .merge(SearchQuery);
10718
10742
  const CustomerSelector = z.z.object({ id: z.z.string() });
10719
10743
  const CustomerApiResponse = BaseCustomer;
10744
+ const TenantSelfResponse = BaseCustomer.extend({
10745
+ workspaceKey: z.z.string().optional(),
10746
+ });
10720
10747
 
10721
10748
  const FieldMappingApiResponse = BaseFieldMapping.extend({
10722
10749
  integration: BaseIntegration.optional(),
@@ -11265,6 +11292,29 @@ const IncomingWebhookApiResponse = z.z.object({
11265
11292
  subscription: BaseExternalEventSubscription.optional(),
11266
11293
  });
11267
11294
 
11295
+ const CreateConnectedProductRequest = z.z.object({
11296
+ name: z.z.string(),
11297
+ type: ConnectedProductType,
11298
+ audience: ConnectedProductAudience.optional(),
11299
+ parameters: AiAgentParameters.optional(),
11300
+ });
11301
+ const UpdateConnectedProductRequest = z.z.object({
11302
+ name: z.z.string().optional(),
11303
+ type: ConnectedProductType.optional(),
11304
+ audience: ConnectedProductAudience.optional(),
11305
+ parameters: AiAgentParameters.optional(),
11306
+ });
11307
+ const FindConnectedProductsQuery = z.z
11308
+ .object({
11309
+ type: ConnectedProductType.optional(),
11310
+ audience: ConnectedProductAudience.optional(),
11311
+ key: z.z.string().optional(),
11312
+ })
11313
+ .merge(PaginationQuery)
11314
+ .merge(SearchQuery)
11315
+ .merge(IncludeArchivedQuery);
11316
+ const ConnectedProductApiResponse = BaseConnectedProduct;
11317
+
11268
11318
  class DependencyError extends MembraneError {
11269
11319
  constructor(arg, workspaceElementReference) {
11270
11320
  super(arg);
@@ -11860,6 +11910,13 @@ const WorkspaceElementSpecs = {
11860
11910
  hasKey: true,
11861
11911
  isProOnly: true,
11862
11912
  },
11913
+ [exports.WorkspaceElementType.ConnectedProduct]: {
11914
+ type: exports.WorkspaceElementType.ConnectedProduct,
11915
+ apiPath: 'connected-products',
11916
+ name: 'Connected Product',
11917
+ namePlural: 'Connected Products',
11918
+ hasKey: true,
11919
+ },
11863
11920
  };
11864
11921
  function getEditablePathsForElementType(elementType) {
11865
11922
  return getEditablePathsForElementType$1(WorkspaceElementSpecs, elementType);
@@ -12836,13 +12893,14 @@ exports.WorkspaceElementChangeType = void 0;
12836
12893
  WorkspaceElementChangeType["DELETE"] = "delete";
12837
12894
  })(exports.WorkspaceElementChangeType || (exports.WorkspaceElementChangeType = {}));
12838
12895
  function compareWorkspaceExports(baseExport, targetExport, options = { includeDeletions: true }) {
12839
- const changes = [];
12896
+ const changes = {};
12840
12897
  const comparison = {
12841
12898
  [exports.WorkspaceElementChangeType.CREATE]: new Set(),
12842
12899
  [exports.WorkspaceElementChangeType.UPDATE]: new Set(),
12843
12900
  [exports.WorkspaceElementChangeType.DELETE]: new Set(),
12844
12901
  };
12845
12902
  const sourceUuidByTargetUuid = new Map();
12903
+ const diffs = [];
12846
12904
  const integrationMap = buildIntegrationsMap([
12847
12905
  ...(baseExport[exports.WorkspaceElementType.Integration] || []),
12848
12906
  ...(targetExport[exports.WorkspaceElementType.Integration] || []),
@@ -12857,35 +12915,46 @@ function compareWorkspaceExports(baseExport, targetExport, options = { includeDe
12857
12915
  for (const element of baseElements) {
12858
12916
  const intIdentifier = getIntegrationIdentifier(element, integrationMap);
12859
12917
  const selector = getElementSelector(type, element.key, intIdentifier);
12860
- baseMap.set(selector, element);
12918
+ baseMap.set(selector, { type, element });
12861
12919
  allSelectors.add(selector);
12862
12920
  }
12863
12921
  const targetElements = targetExport[type] || [];
12864
12922
  for (const element of targetElements) {
12865
12923
  const intIdentifier = getIntegrationIdentifier(element, integrationMap);
12866
12924
  const selector = getElementSelector(type, element.key, intIdentifier);
12867
- targetMap.set(selector, element);
12925
+ targetMap.set(selector, { type, element });
12868
12926
  allSelectors.add(selector);
12869
12927
  }
12870
12928
  }
12871
12929
  for (const selector of allSelectors) {
12872
- const baseElement = baseMap.get(selector);
12873
- const targetElement = targetMap.get(selector);
12874
- if (baseElement && targetElement && baseElement.uuid !== targetElement.uuid) {
12875
- sourceUuidByTargetUuid.set(targetElement.uuid, baseElement.uuid);
12930
+ const base = baseMap.get(selector);
12931
+ const target = targetMap.get(selector);
12932
+ if (base && target && base.element.uuid !== target.element.uuid) {
12933
+ sourceUuidByTargetUuid.set(target.element.uuid, base.element.uuid);
12876
12934
  }
12877
- const change = compareElementExports(baseElement, targetElement);
12935
+ const change = compareElementExports(base === null || base === void 0 ? void 0 : base.element, target === null || target === void 0 ? void 0 : target.element);
12878
12936
  if (options.includeDeletions === false && (change === null || change === void 0 ? void 0 : change.type) === exports.WorkspaceElementChangeType.DELETE) {
12879
12937
  continue;
12880
12938
  }
12881
- if (change) {
12882
- changes.push(change);
12939
+ if (!change) {
12940
+ continue;
12883
12941
  }
12884
- }
12885
- changes.forEach((change) => {
12942
+ const subject = target || base;
12943
+ const integrationKey = getIntegrationIdentifier(subject.element, integrationMap);
12944
+ const path = getMembraneElementPath(subject.type, subject.element.key, integrationKey);
12945
+ changes[change.uuid] = { elementType: subject.type, path };
12886
12946
  comparison[change.type].add(change.uuid);
12887
- });
12888
- return { comparison, sourceUuidByTargetUuid };
12947
+ if (options.includeDiff) {
12948
+ const baseYaml = base ? yaml__namespace.dump(base.element) : '';
12949
+ const targetYaml = target ? yaml__namespace.dump(target.element) : '';
12950
+ diffs.push(diff.createTwoFilesPatch(`a/${path}`, `b/${path}`, baseYaml, targetYaml));
12951
+ }
12952
+ }
12953
+ const result = { comparison, changes, sourceUuidByTargetUuid };
12954
+ if (options.includeDiff) {
12955
+ result.diff = diffs.join('\n').trim();
12956
+ }
12957
+ return result;
12889
12958
  }
12890
12959
  function compareElementExports(baseElement, targetElement) {
12891
12960
  if (baseElement && !targetElement) {
@@ -12938,7 +13007,7 @@ function buildIntegrationsMap(integrations) {
12938
13007
  return map;
12939
13008
  }
12940
13009
 
12941
- const IneligibilityReasonSchema = z.z.enum(['disposable', 'blockedDomain', 'notCompanyEmail']);
13010
+ const IneligibilityReasonSchema = z.z.enum(['disposable', 'blockedDomain']);
12942
13011
  const PlatformUser = z.z.object({
12943
13012
  id: z.z.string(),
12944
13013
  email: z.z.string(),
@@ -12961,6 +13030,7 @@ const FullPlatformUser = z.z.object({
12961
13030
  isEligible: z.z.boolean().optional(),
12962
13031
  ineligibilityReason: IneligibilityReasonSchema.optional(),
12963
13032
  emailVerified: z.z.boolean().optional(),
13033
+ isCompanyEmail: z.z.boolean().optional(),
12964
13034
  });
12965
13035
 
12966
13036
  exports.OrgLimitsType = void 0;
@@ -14517,6 +14587,7 @@ async function createOrUpdateConnection(options) {
14517
14587
  const { stopSSE } = createSSEListener({
14518
14588
  apiUri: apiUri,
14519
14589
  requestId,
14590
+ token,
14520
14591
  handler: eventHandler,
14521
14592
  });
14522
14593
  function cleanup() {
@@ -14631,8 +14702,8 @@ const createCrossWindowListener = ({ handler }) => {
14631
14702
  },
14632
14703
  };
14633
14704
  };
14634
- const createSSEListener = ({ apiUri, requestId, handler, }) => {
14635
- const sseUrl = urljoin(apiUri, '/sse/connection-events', requestId);
14705
+ const createSSEListener = ({ apiUri, requestId, token, handler, }) => {
14706
+ const sseUrl = urljoin(apiUri, '/sse/connection-events', requestId) + `?token=${encodeURIComponent(token)}`;
14636
14707
  let eventSource = null;
14637
14708
  const closeSseConnection = () => {
14638
14709
  eventSource === null || eventSource === void 0 ? void 0 : eventSource.close();
@@ -15168,7 +15239,9 @@ const AgentSession = z.z.object({
15168
15239
  status: z.z.enum(exports.AgentSessionStatus),
15169
15240
  prompt: z.z.string(),
15170
15241
  error: ErrorDataSchema.optional(),
15171
- lastActivityAt: z.z.iso.datetime(),
15242
+ lastActivityAt: z.z.iso
15243
+ .datetime()
15244
+ .describe('Last meaningful session progress timestamp used for inactivity timeout checks.'),
15172
15245
  title: z.z.string().optional(),
15173
15246
  summary: z.z.string().optional(),
15174
15247
  cost: z.z.number().optional(),
@@ -15195,7 +15268,10 @@ const AgentSessionInputSchema = z.z.object({
15195
15268
  });
15196
15269
  const PatchAgentSessionSchema = z.z.object({
15197
15270
  state: z.z.enum(exports.AgentSessionState).optional(),
15198
- lastActivityAt: z.z.iso.datetime().optional(),
15271
+ lastActivityAt: z.z.iso
15272
+ .datetime()
15273
+ .optional()
15274
+ .describe('Last meaningful session progress timestamp used for inactivity timeout checks.'),
15199
15275
  title: z.z.string().optional(),
15200
15276
  summary: z.z.string().optional(),
15201
15277
  cost: z.z.number().optional(),
@@ -15272,14 +15348,18 @@ const ClientToken = z.z.object({
15272
15348
  grantType: ClientTokenGrantType,
15273
15349
  grantId: z.z.string().optional(),
15274
15350
  grantName: z.z.string().optional(),
15275
- accessToken: z.z.string().optional(),
15351
+ connectedProductId: z.z.string().optional(),
15276
15352
  createdAt: z.z.string(),
15277
15353
  });
15354
+ const CreateClientTokenResponse = ClientToken.extend({
15355
+ accessToken: z.z.string(),
15356
+ });
15278
15357
  const CreateClientTokenRequest = z.z.object({
15279
15358
  grantType: ClientTokenGrantType,
15280
15359
  grantId: z.z.string(),
15281
15360
  grantName: z.z.string(),
15282
15361
  tenantId: z.z.string().optional(),
15362
+ productKey: z.z.string().optional(),
15283
15363
  });
15284
15364
  const ClientTokenListResponse = z.z.object({
15285
15365
  items: z.z.array(ClientToken),
@@ -15294,8 +15374,8 @@ const OAuthTokenResponse = z.z.object({
15294
15374
  token_type: z.z.string(),
15295
15375
  expires_in: z.z.number(),
15296
15376
  refresh_token: z.z.string().optional(),
15297
- default_workspace_id: z.z.string().optional(),
15298
- default_tenant_id: z.z.string().optional(),
15377
+ default_workspace_key: z.z.string().optional(),
15378
+ default_tenant_key: z.z.string().optional(),
15299
15379
  });
15300
15380
 
15301
15381
  const CONSOLE_ACCOUNT_API_TOKEN_PATH = 'settings/account/api-token';
@@ -15937,6 +16017,9 @@ exports.ActivityLogRecord = ActivityLogRecord;
15937
16017
  exports.ActivityStatsQuery = ActivityStatsQuery;
15938
16018
  exports.AgentSession = AgentSession;
15939
16019
  exports.AgentSessionInputSchema = AgentSessionInputSchema;
16020
+ exports.AiAgentAudience = AiAgentAudience;
16021
+ exports.AiAgentParameters = AiAgentParameters;
16022
+ exports.AiAgentType = AiAgentType;
15940
16023
  exports.Alert = Alert;
15941
16024
  exports.AlertDeliverySettingsSchema = AlertDeliverySettingsSchema;
15942
16025
  exports.AlertSchema = AlertSchema;
@@ -15972,6 +16055,7 @@ exports.BaseAppDataSchema = BaseAppDataSchema;
15972
16055
  exports.BaseAppDataSchemaInstance = BaseAppDataSchemaInstance;
15973
16056
  exports.BaseAppEventSubscription = BaseAppEventSubscription;
15974
16057
  exports.BaseAppEventType = BaseAppEventType;
16058
+ exports.BaseConnectedProduct = BaseConnectedProduct;
15975
16059
  exports.BaseConnection = BaseConnection;
15976
16060
  exports.BaseConnector = BaseConnector;
15977
16061
  exports.BaseCustomer = BaseCustomer;
@@ -16031,6 +16115,9 @@ exports.ConcurrencyError = ConcurrencyError;
16031
16115
  exports.ConfigurationError = ConfigurationError;
16032
16116
  exports.ConnectPayload = ConnectPayload;
16033
16117
  exports.ConnectUIOptions = ConnectUIOptions;
16118
+ exports.ConnectedProductApiResponse = ConnectedProductApiResponse;
16119
+ exports.ConnectedProductAudience = ConnectedProductAudience;
16120
+ exports.ConnectedProductType = ConnectedProductType;
16034
16121
  exports.ConnectionAccessor = ConnectionAccessor;
16035
16122
  exports.ConnectionApiResponse = ConnectionApiResponse;
16036
16123
  exports.ConnectionApiResponseWithSecrets = ConnectionApiResponseWithSecrets;
@@ -16100,6 +16187,8 @@ exports.CreateActionRequest = CreateActionRequest;
16100
16187
  exports.CreateAgentSession = CreateAgentSession;
16101
16188
  exports.CreateAlert = CreateAlert;
16102
16189
  exports.CreateClientTokenRequest = CreateClientTokenRequest;
16190
+ exports.CreateClientTokenResponse = CreateClientTokenResponse;
16191
+ exports.CreateConnectedProductRequest = CreateConnectedProductRequest;
16103
16192
  exports.CreateConnectionRequest = CreateConnectionRequest;
16104
16193
  exports.CreateConnectionRequestPayload = CreateConnectionRequestPayload;
16105
16194
  exports.CreateConnectorRequest = CreateConnectorRequest;
@@ -16233,6 +16322,7 @@ exports.FindAppDataSchemasQuery = FindAppDataSchemasQuery;
16233
16322
  exports.FindAppEventSubscriptionsQuery = FindAppEventSubscriptionsQuery;
16234
16323
  exports.FindAppEventTypesQuery = FindAppEventTypesQuery;
16235
16324
  exports.FindAppEventsQuery = FindAppEventsQuery;
16325
+ exports.FindConnectedProductsQuery = FindConnectedProductsQuery;
16236
16326
  exports.FindConnectionsQuery = FindConnectionsQuery;
16237
16327
  exports.FindConnectionsResponse = FindConnectionsResponse;
16238
16328
  exports.FindCustomersQuery = FindCustomersQuery;
@@ -16416,10 +16506,12 @@ exports.SessionCredentials = SessionCredentials;
16416
16506
  exports.SessionParameters = SessionParameters;
16417
16507
  exports.StatsFilterQuery = StatsFilterQuery;
16418
16508
  exports.TenantLayerElement = TenantLayerElement;
16509
+ exports.TenantSelfResponse = TenantSelfResponse;
16419
16510
  exports.UNIFIED_DATA_MODELS = UNIFIED_DATA_MODELS;
16420
16511
  exports.UnitRunError = UnitRunError;
16421
16512
  exports.UpdateActionInstanceRequest = UpdateActionInstanceRequest;
16422
16513
  exports.UpdateActionRequest = UpdateActionRequest;
16514
+ exports.UpdateConnectedProductRequest = UpdateConnectedProductRequest;
16423
16515
  exports.UpdateConnectionRequest = UpdateConnectionRequest;
16424
16516
  exports.UpdateConnectorRequest = UpdateConnectorRequest;
16425
16517
  exports.UpdateCustomerRequest = UpdateCustomerRequest;