@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,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(),
@@ -10693,6 +10737,9 @@ const FindCustomersQuery = z.z
10693
10737
  .merge(SearchQuery);
10694
10738
  const CustomerSelector = z.z.object({ id: z.z.string() });
10695
10739
  const CustomerApiResponse = BaseCustomer;
10740
+ const TenantSelfResponse = BaseCustomer.extend({
10741
+ workspaceKey: z.z.string().optional(),
10742
+ });
10696
10743
 
10697
10744
  const FieldMappingApiResponse = BaseFieldMapping.extend({
10698
10745
  integration: BaseIntegration.optional(),
@@ -11241,6 +11288,29 @@ const IncomingWebhookApiResponse = z.z.object({
11241
11288
  subscription: BaseExternalEventSubscription.optional(),
11242
11289
  });
11243
11290
 
11291
+ const CreateConnectedProductRequest = z.z.object({
11292
+ name: z.z.string(),
11293
+ type: ConnectedProductType,
11294
+ audience: ConnectedProductAudience.optional(),
11295
+ parameters: AiAgentParameters.optional(),
11296
+ });
11297
+ const UpdateConnectedProductRequest = z.z.object({
11298
+ name: z.z.string().optional(),
11299
+ type: ConnectedProductType.optional(),
11300
+ audience: ConnectedProductAudience.optional(),
11301
+ parameters: AiAgentParameters.optional(),
11302
+ });
11303
+ const FindConnectedProductsQuery = z.z
11304
+ .object({
11305
+ type: ConnectedProductType.optional(),
11306
+ audience: ConnectedProductAudience.optional(),
11307
+ key: z.z.string().optional(),
11308
+ })
11309
+ .merge(PaginationQuery)
11310
+ .merge(SearchQuery)
11311
+ .merge(IncludeArchivedQuery);
11312
+ const ConnectedProductApiResponse = BaseConnectedProduct;
11313
+
11244
11314
  class DependencyError extends MembraneError {
11245
11315
  constructor(arg, workspaceElementReference) {
11246
11316
  super(arg);
@@ -11836,6 +11906,13 @@ const WorkspaceElementSpecs = {
11836
11906
  hasKey: true,
11837
11907
  isProOnly: true,
11838
11908
  },
11909
+ [exports.WorkspaceElementType.ConnectedProduct]: {
11910
+ type: exports.WorkspaceElementType.ConnectedProduct,
11911
+ apiPath: 'connected-products',
11912
+ name: 'Connected Product',
11913
+ namePlural: 'Connected Products',
11914
+ hasKey: true,
11915
+ },
11839
11916
  };
11840
11917
  function getEditablePathsForElementType(elementType) {
11841
11918
  return getEditablePathsForElementType$1(WorkspaceElementSpecs, elementType);
@@ -12812,13 +12889,14 @@ exports.WorkspaceElementChangeType = void 0;
12812
12889
  WorkspaceElementChangeType["DELETE"] = "delete";
12813
12890
  })(exports.WorkspaceElementChangeType || (exports.WorkspaceElementChangeType = {}));
12814
12891
  function compareWorkspaceExports(baseExport, targetExport, options = { includeDeletions: true }) {
12815
- const changes = [];
12892
+ const changes = {};
12816
12893
  const comparison = {
12817
12894
  [exports.WorkspaceElementChangeType.CREATE]: new Set(),
12818
12895
  [exports.WorkspaceElementChangeType.UPDATE]: new Set(),
12819
12896
  [exports.WorkspaceElementChangeType.DELETE]: new Set(),
12820
12897
  };
12821
12898
  const sourceUuidByTargetUuid = new Map();
12899
+ const diffs = [];
12822
12900
  const integrationMap = buildIntegrationsMap([
12823
12901
  ...(baseExport[exports.WorkspaceElementType.Integration] || []),
12824
12902
  ...(targetExport[exports.WorkspaceElementType.Integration] || []),
@@ -12833,35 +12911,46 @@ function compareWorkspaceExports(baseExport, targetExport, options = { includeDe
12833
12911
  for (const element of baseElements) {
12834
12912
  const intIdentifier = getIntegrationIdentifier(element, integrationMap);
12835
12913
  const selector = getElementSelector(type, element.key, intIdentifier);
12836
- baseMap.set(selector, element);
12914
+ baseMap.set(selector, { type, element });
12837
12915
  allSelectors.add(selector);
12838
12916
  }
12839
12917
  const targetElements = targetExport[type] || [];
12840
12918
  for (const element of targetElements) {
12841
12919
  const intIdentifier = getIntegrationIdentifier(element, integrationMap);
12842
12920
  const selector = getElementSelector(type, element.key, intIdentifier);
12843
- targetMap.set(selector, element);
12921
+ targetMap.set(selector, { type, element });
12844
12922
  allSelectors.add(selector);
12845
12923
  }
12846
12924
  }
12847
12925
  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);
12926
+ const base = baseMap.get(selector);
12927
+ const target = targetMap.get(selector);
12928
+ if (base && target && base.element.uuid !== target.element.uuid) {
12929
+ sourceUuidByTargetUuid.set(target.element.uuid, base.element.uuid);
12852
12930
  }
12853
- const change = compareElementExports(baseElement, targetElement);
12931
+ const change = compareElementExports(base === null || base === void 0 ? void 0 : base.element, target === null || target === void 0 ? void 0 : target.element);
12854
12932
  if (options.includeDeletions === false && (change === null || change === void 0 ? void 0 : change.type) === exports.WorkspaceElementChangeType.DELETE) {
12855
12933
  continue;
12856
12934
  }
12857
- if (change) {
12858
- changes.push(change);
12935
+ if (!change) {
12936
+ continue;
12859
12937
  }
12860
- }
12861
- changes.forEach((change) => {
12938
+ const subject = target || base;
12939
+ const integrationKey = getIntegrationIdentifier(subject.element, integrationMap);
12940
+ const path = getMembraneElementPath(subject.type, subject.element.key, integrationKey);
12941
+ changes[change.uuid] = { elementType: subject.type, path };
12862
12942
  comparison[change.type].add(change.uuid);
12863
- });
12864
- return { comparison, sourceUuidByTargetUuid };
12943
+ if (options.includeDiff) {
12944
+ const baseYaml = base ? yaml__namespace.dump(base.element) : '';
12945
+ const targetYaml = target ? yaml__namespace.dump(target.element) : '';
12946
+ diffs.push(diff.createTwoFilesPatch(`a/${path}`, `b/${path}`, baseYaml, targetYaml));
12947
+ }
12948
+ }
12949
+ const result = { comparison, changes, sourceUuidByTargetUuid };
12950
+ if (options.includeDiff) {
12951
+ result.diff = diffs.join('\n').trim();
12952
+ }
12953
+ return result;
12865
12954
  }
12866
12955
  function compareElementExports(baseElement, targetElement) {
12867
12956
  if (baseElement && !targetElement) {
@@ -12914,7 +13003,7 @@ function buildIntegrationsMap(integrations) {
12914
13003
  return map;
12915
13004
  }
12916
13005
 
12917
- const IneligibilityReasonSchema = z.z.enum(['disposable', 'blockedDomain', 'notCompanyEmail']);
13006
+ const IneligibilityReasonSchema = z.z.enum(['disposable', 'blockedDomain']);
12918
13007
  const PlatformUser = z.z.object({
12919
13008
  id: z.z.string(),
12920
13009
  email: z.z.string(),
@@ -12937,6 +13026,7 @@ const FullPlatformUser = z.z.object({
12937
13026
  isEligible: z.z.boolean().optional(),
12938
13027
  ineligibilityReason: IneligibilityReasonSchema.optional(),
12939
13028
  emailVerified: z.z.boolean().optional(),
13029
+ isCompanyEmail: z.z.boolean().optional(),
12940
13030
  });
12941
13031
 
12942
13032
  exports.OrgLimitsType = void 0;
@@ -14493,6 +14583,7 @@ async function createOrUpdateConnection(options) {
14493
14583
  const { stopSSE } = createSSEListener({
14494
14584
  apiUri: apiUri,
14495
14585
  requestId,
14586
+ token,
14496
14587
  handler: eventHandler,
14497
14588
  });
14498
14589
  function cleanup() {
@@ -14607,8 +14698,8 @@ const createCrossWindowListener = ({ handler }) => {
14607
14698
  },
14608
14699
  };
14609
14700
  };
14610
- const createSSEListener = ({ apiUri, requestId, handler, }) => {
14611
- const sseUrl = urljoin(apiUri, '/sse/connection-events', requestId);
14701
+ const createSSEListener = ({ apiUri, requestId, token, handler, }) => {
14702
+ const sseUrl = urljoin(apiUri, '/sse/connection-events', requestId) + `?token=${encodeURIComponent(token)}`;
14612
14703
  let eventSource = null;
14613
14704
  const closeSseConnection = () => {
14614
14705
  eventSource === null || eventSource === void 0 ? void 0 : eventSource.close();
@@ -15144,7 +15235,9 @@ const AgentSession = z.z.object({
15144
15235
  status: z.z.enum(exports.AgentSessionStatus),
15145
15236
  prompt: z.z.string(),
15146
15237
  error: ErrorDataSchema.optional(),
15147
- lastActivityAt: z.z.iso.datetime(),
15238
+ lastActivityAt: z.z.iso
15239
+ .datetime()
15240
+ .describe('Last meaningful session progress timestamp used for inactivity timeout checks.'),
15148
15241
  title: z.z.string().optional(),
15149
15242
  summary: z.z.string().optional(),
15150
15243
  cost: z.z.number().optional(),
@@ -15171,7 +15264,10 @@ const AgentSessionInputSchema = z.z.object({
15171
15264
  });
15172
15265
  const PatchAgentSessionSchema = z.z.object({
15173
15266
  state: z.z.enum(exports.AgentSessionState).optional(),
15174
- lastActivityAt: z.z.iso.datetime().optional(),
15267
+ lastActivityAt: z.z.iso
15268
+ .datetime()
15269
+ .optional()
15270
+ .describe('Last meaningful session progress timestamp used for inactivity timeout checks.'),
15175
15271
  title: z.z.string().optional(),
15176
15272
  summary: z.z.string().optional(),
15177
15273
  cost: z.z.number().optional(),
@@ -15248,14 +15344,18 @@ const ClientToken = z.z.object({
15248
15344
  grantType: ClientTokenGrantType,
15249
15345
  grantId: z.z.string().optional(),
15250
15346
  grantName: z.z.string().optional(),
15251
- accessToken: z.z.string().optional(),
15347
+ connectedProductId: z.z.string().optional(),
15252
15348
  createdAt: z.z.string(),
15253
15349
  });
15350
+ const CreateClientTokenResponse = ClientToken.extend({
15351
+ accessToken: z.z.string(),
15352
+ });
15254
15353
  const CreateClientTokenRequest = z.z.object({
15255
15354
  grantType: ClientTokenGrantType,
15256
15355
  grantId: z.z.string(),
15257
15356
  grantName: z.z.string(),
15258
15357
  tenantId: z.z.string().optional(),
15358
+ productKey: z.z.string().optional(),
15259
15359
  });
15260
15360
  const ClientTokenListResponse = z.z.object({
15261
15361
  items: z.z.array(ClientToken),
@@ -15270,8 +15370,8 @@ const OAuthTokenResponse = z.z.object({
15270
15370
  token_type: z.z.string(),
15271
15371
  expires_in: z.z.number(),
15272
15372
  refresh_token: z.z.string().optional(),
15273
- default_workspace_id: z.z.string().optional(),
15274
- default_tenant_id: z.z.string().optional(),
15373
+ default_workspace_key: z.z.string().optional(),
15374
+ default_tenant_key: z.z.string().optional(),
15275
15375
  });
15276
15376
 
15277
15377
  const CONSOLE_ACCOUNT_API_TOKEN_PATH = 'settings/account/api-token';
@@ -15733,6 +15833,9 @@ exports.ActivityLogRecord = ActivityLogRecord;
15733
15833
  exports.ActivityStatsQuery = ActivityStatsQuery;
15734
15834
  exports.AgentSession = AgentSession;
15735
15835
  exports.AgentSessionInputSchema = AgentSessionInputSchema;
15836
+ exports.AiAgentAudience = AiAgentAudience;
15837
+ exports.AiAgentParameters = AiAgentParameters;
15838
+ exports.AiAgentType = AiAgentType;
15736
15839
  exports.Alert = Alert;
15737
15840
  exports.AlertDeliverySettingsSchema = AlertDeliverySettingsSchema;
15738
15841
  exports.AlertSchema = AlertSchema;
@@ -15768,6 +15871,7 @@ exports.BaseAppDataSchema = BaseAppDataSchema;
15768
15871
  exports.BaseAppDataSchemaInstance = BaseAppDataSchemaInstance;
15769
15872
  exports.BaseAppEventSubscription = BaseAppEventSubscription;
15770
15873
  exports.BaseAppEventType = BaseAppEventType;
15874
+ exports.BaseConnectedProduct = BaseConnectedProduct;
15771
15875
  exports.BaseConnection = BaseConnection;
15772
15876
  exports.BaseConnector = BaseConnector;
15773
15877
  exports.BaseCustomer = BaseCustomer;
@@ -15826,6 +15930,9 @@ exports.ConcurrencyError = ConcurrencyError;
15826
15930
  exports.ConfigurationError = ConfigurationError;
15827
15931
  exports.ConnectPayload = ConnectPayload;
15828
15932
  exports.ConnectUIOptions = ConnectUIOptions;
15933
+ exports.ConnectedProductApiResponse = ConnectedProductApiResponse;
15934
+ exports.ConnectedProductAudience = ConnectedProductAudience;
15935
+ exports.ConnectedProductType = ConnectedProductType;
15829
15936
  exports.ConnectionAccessor = ConnectionAccessor;
15830
15937
  exports.ConnectionApiResponse = ConnectionApiResponse;
15831
15938
  exports.ConnectionApiResponseWithSecrets = ConnectionApiResponseWithSecrets;
@@ -15895,6 +16002,8 @@ exports.CreateActionRequest = CreateActionRequest;
15895
16002
  exports.CreateAgentSession = CreateAgentSession;
15896
16003
  exports.CreateAlert = CreateAlert;
15897
16004
  exports.CreateClientTokenRequest = CreateClientTokenRequest;
16005
+ exports.CreateClientTokenResponse = CreateClientTokenResponse;
16006
+ exports.CreateConnectedProductRequest = CreateConnectedProductRequest;
15898
16007
  exports.CreateConnectionRequest = CreateConnectionRequest;
15899
16008
  exports.CreateConnectionRequestPayload = CreateConnectionRequestPayload;
15900
16009
  exports.CreateConnectorRequest = CreateConnectorRequest;
@@ -16028,6 +16137,7 @@ exports.FindAppDataSchemasQuery = FindAppDataSchemasQuery;
16028
16137
  exports.FindAppEventSubscriptionsQuery = FindAppEventSubscriptionsQuery;
16029
16138
  exports.FindAppEventTypesQuery = FindAppEventTypesQuery;
16030
16139
  exports.FindAppEventsQuery = FindAppEventsQuery;
16140
+ exports.FindConnectedProductsQuery = FindConnectedProductsQuery;
16031
16141
  exports.FindConnectionsQuery = FindConnectionsQuery;
16032
16142
  exports.FindConnectionsResponse = FindConnectionsResponse;
16033
16143
  exports.FindCustomersQuery = FindCustomersQuery;
@@ -16210,10 +16320,12 @@ exports.SessionCredentials = SessionCredentials;
16210
16320
  exports.SessionParameters = SessionParameters;
16211
16321
  exports.StatsFilterQuery = StatsFilterQuery;
16212
16322
  exports.TenantLayerElement = TenantLayerElement;
16323
+ exports.TenantSelfResponse = TenantSelfResponse;
16213
16324
  exports.UNIFIED_DATA_MODELS = UNIFIED_DATA_MODELS;
16214
16325
  exports.UnitRunError = UnitRunError;
16215
16326
  exports.UpdateActionInstanceRequest = UpdateActionInstanceRequest;
16216
16327
  exports.UpdateActionRequest = UpdateActionRequest;
16328
+ exports.UpdateConnectedProductRequest = UpdateConnectedProductRequest;
16217
16329
  exports.UpdateConnectionRequest = UpdateConnectionRequest;
16218
16330
  exports.UpdateConnectorRequest = UpdateConnectorRequest;
16219
16331
  exports.UpdateCustomerRequest = UpdateCustomerRequest;