@stackable-labs/sdk-extension-contracts 1.69.2 → 1.71.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.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import { MarketplaceMetadata } from '@stackable-labs/lib-contracts';
2
- export { AppRegistryEntry, EXTENSION_CATEGORIES, EXTENSION_VISIBILITIES, ExtensionCategory, ExtensionVisibility, MarketplaceMetadata } from '@stackable-labs/lib-contracts';
1
+ import { ISOTimestamp, MarketplaceMetadata } from '@stackable-labs/lib-contracts';
2
+ export { AppRegistryEntry, ClerkOrgId, ClerkUserId, EXTENSION_CATEGORIES, EXTENSION_VISIBILITIES, ExtensionCategory, ExtensionVisibility, ISOTimestamp, MarketplaceMetadata, asClerkOrgId, asClerkUserId, asISOTimestamp } from '@stackable-labs/lib-contracts';
3
3
 
4
4
  /**
5
5
  * Shared primitive types used across contracts.
6
6
  */
7
+
7
8
  /** Lightweight reference to a named entity (e.g. extension, instance). */
8
9
  interface NamedEntity {
9
10
  id: string;
@@ -324,30 +325,13 @@ declare const tagToComponentName: (tag: UITag) => string;
324
325
  declare const ALLOWED_ICONS: readonly ["arrow-left", "calendar", "check-circle-2", "chevron-left", "chevron-right", "clock", "credit-card", "external-link", "help-circle", "info", "loader-2", "mail", "map-pin", "message-circle", "message-square", "package", "phone", "search", "shopping-bag", "sparkles", "truck", "user", "x-circle", "alert-circle", "book-open"];
325
326
  type AllowedIconName = (typeof ALLOWED_ICONS)[number];
326
327
 
327
- /**
328
- * Messaging Contract
329
- * Types for the messaging event system (postback buttons, etc.).
330
- */
331
- /** Messaging event subscription types — 'postback' for all, 'postback:<actionName>' for specific */
332
- type MessagingEventType = 'postback' | `postback:${string}`;
333
- /** Normalized postback event payload */
334
- interface MessagingPostbackEvent {
335
- type: 'postback';
336
- actionName: string;
337
- conversationId: string;
338
- timestamp: string;
339
- }
340
- /** Union of all messaging events (extensible for future event types) */
341
- type MessagingEvent = MessagingPostbackEvent;
342
- /** Handler type for useMessagingEvent — use with useCallback for memoized handlers */
343
- type MessagingEventHandler = (event: MessagingEvent) => void;
344
-
345
328
  /**
346
329
  * Identity & Event Contract
347
- * Types for the identity/auth event system and cross-domain event declarations.
330
+ * Types for the identity/auth event system.
348
331
  */
349
332
 
350
- type IdentityEventType = 'identity.login' | 'identity.logout' | 'identity.refresh' | 'identity.expired';
333
+ /** Domain-stripped identity event names. Hooks accept these directly (e.g., useIdentityEvent('login', ...)). */
334
+ type IdentityEventType = 'login' | 'logout' | 'refresh' | 'expired';
351
335
  interface UserIdentity {
352
336
  id: string;
353
337
  email?: string;
@@ -359,19 +343,15 @@ interface UserIdentity {
359
343
  interface IdentityState {
360
344
  authenticated: boolean;
361
345
  user: UserIdentity | null;
362
- expiresAt?: string;
346
+ expiresAt?: ISOTimestamp;
363
347
  }
364
348
  interface IdentityEvent {
365
- type: IdentityEventType;
366
- state: IdentityState;
367
- timestamp: string;
349
+ eventName: IdentityEventType;
350
+ data: {
351
+ state: IdentityState;
352
+ timestamp: ISOTimestamp;
353
+ };
368
354
  }
369
- /**
370
- * Union of all event types that can appear in the manifest events array.
371
- * Grows as new event domains are added.
372
- * Includes domain wildcards (e.g. 'identity' matches all identity.* events).
373
- */
374
- type EventType = IdentityEventType | 'identity' | MessagingEventType | 'messaging';
375
355
  /** Base claims sent to extend:identity handlers before JWT signing */
376
356
  interface IdentityBaseClaims {
377
357
  external_id: string;
@@ -481,6 +461,68 @@ type CapabilityCall = {
481
461
  };
482
462
  type CapabilityType = CapabilityCall['type'];
483
463
 
464
+ /**
465
+ * Messaging Contract
466
+ * Types for the messaging event system (postback buttons, etc.).
467
+ */
468
+
469
+ /** Messaging event subscription types — 'postback' for all, 'postback:<actionName>' for specific */
470
+ type MessagingEventType = 'postback' | `postback:${string}`;
471
+ /** Normalized postback event payload */
472
+ interface MessagingPostbackEvent {
473
+ eventName: 'postback';
474
+ data: {
475
+ /**
476
+ * The postback button's display text (Zendesk-specific).
477
+ * NOTE: This is NOT an event system field — `eventType` and `eventName` are our event system
478
+ * conventions. `actionName` is a domain-specific payload field identifying which button was
479
+ * clicked, and lives inside `data` alongside other Zendesk messaging fields.
480
+ */
481
+ actionName: string;
482
+ conversationId: string;
483
+ timestamp: ISOTimestamp;
484
+ };
485
+ }
486
+ /** Union of all messaging events (extensible for future event types) */
487
+ type MessagingEvent = MessagingPostbackEvent;
488
+ /** Handler type for useMessagingEvent — use with useCallback for memoized handlers */
489
+ type MessagingEventHandler = (event: MessagingEvent) => void;
490
+
491
+ /**
492
+ * Activity Event Contract
493
+ * Types for the activity event system (host-to-extension push events).
494
+ */
495
+ /** Well-known activity event names (aligned with GA conventions). Hosts can emit any custom string. */
496
+ type WellKnownActivityEvent = 'page_view' | 'click' | 'product_view' | 'add_to_cart' | 'purchase' | 'search' | 'form_submit';
497
+ /** Domain-stripped activity event names. Hooks accept these directly (e.g., useActivityEvent('product_view', ...)). */
498
+ type ActivityEventType = WellKnownActivityEvent | string;
499
+ /** Normalized activity event payload */
500
+ interface ActivityEvent {
501
+ eventName: ActivityEventType;
502
+ data: Record<string, unknown>;
503
+ }
504
+ /** Handler type for useActivityEvent — use with useCallback for memoized handlers */
505
+ type ActivityEventHandler = (event: ActivityEvent) => void;
506
+
507
+ /**
508
+ * Unified Event Type
509
+ * Shared union across all event domains. Used in manifest `events` array and the generic `useEvent` hook.
510
+ * Domain-specific hooks accept the un-prefixed types (e.g., 'login' not 'identity:login').
511
+ */
512
+
513
+ /** Known event domains. Used by window.stackable.emit() and broadcast routing. */
514
+ type EventDomain = 'activity' | 'identity' | 'messaging';
515
+ /** Domain-specific event type mapping. Maps each domain to its event name union. */
516
+ type EventTypeMap = {
517
+ activity: ActivityEventType;
518
+ identity: IdentityEventType;
519
+ messaging: MessagingEventType;
520
+ };
521
+ /** Fully-qualified event type: domain wildcard or domain:eventName. Used in manifest `events` array and `useEvent` hook. */
522
+ type EventType = EventDomain | {
523
+ [D in EventDomain]: `${D}:${EventTypeMap[D]}`;
524
+ }[EventDomain];
525
+
484
526
  /**
485
527
  * Instance Contract
486
528
  * Shared types for extension instances used by both host and admin.
@@ -507,7 +549,7 @@ interface InstanceOption {
507
549
  * Extensions declare required permissions in their manifest.
508
550
  * Host enforces: capability calls must be a subset of granted permissions.
509
551
  */
510
- declare const PERMISSIONS: readonly ["context:read", "data:query", "data:fetch", "actions:toast", "actions:invoke", "events:identity", "events:messaging", "extend:identity"];
552
+ declare const PERMISSIONS: readonly ["context:read", "data:query", "data:fetch", "actions:toast", "actions:invoke", "events:identity", "events:messaging", "events:activity", "extend:identity"];
511
553
  type Permission = (typeof PERMISSIONS)[number];
512
554
  /**
513
555
  * Maps capability types to the permission required to use them.
@@ -533,7 +575,7 @@ interface ExtensionManifest {
533
575
  targets: string[];
534
576
  /** Permissions required by this extension */
535
577
  permissions: Permission[];
536
- /** Specific events this extension listens for (e.g. ["identity.login", "postback:add_to_cart"]) */
578
+ /** Specific events this extension listens for (e.g. ["identity:login", "messaging:postback:add_to_cart"]) */
537
579
  events?: EventType[];
538
580
  /**
539
581
  * Hostnames this extension is permitted to reach via data.fetch.
@@ -652,6 +694,7 @@ type SandboxToHostMessage = CapabilityRequest | {
652
694
  * Ecommerce Type Definitions
653
695
  * Ported from zendesk-embedded-widget/app/src/types/ecommerce.ts
654
696
  */
697
+
655
698
  interface Price {
656
699
  currency: string;
657
700
  amount: number;
@@ -756,8 +799,8 @@ interface OrderItem {
756
799
  meta: {
757
800
  entity_id?: string;
758
801
  timestamps: {
759
- created_at: string;
760
- updated_at: string;
802
+ created_at: ISOTimestamp;
803
+ updated_at: ISOTimestamp;
761
804
  };
762
805
  actions?: Array<{
763
806
  id: string;
@@ -813,7 +856,7 @@ interface OrderItem {
813
856
  }>;
814
857
  name?: string;
815
858
  timestamps?: {
816
- created_at: string;
859
+ created_at: ISOTimestamp;
817
860
  };
818
861
  }>;
819
862
  };
@@ -861,8 +904,8 @@ interface Order {
861
904
  };
862
905
  meta: {
863
906
  timestamps: {
864
- created_at: string;
865
- updated_at: string;
907
+ created_at: ISOTimestamp;
908
+ updated_at: ISOTimestamp;
866
909
  };
867
910
  tax_mode: string;
868
911
  entity_id: string;
@@ -884,4 +927,4 @@ interface Order {
884
927
  display_status?: OrderStatus;
885
928
  }
886
929
 
887
- export { ALLOWED_ICONS, type ActionInvokePayload, type Address, type AllowedIconName, type ApiError, type ApiRequest, type ApiResponse, CAPABILITY_PERMISSION_MAP, type CapabilityCall, type CapabilityRequest, type CapabilityResponse, type CapabilityType, type ContextData, type Customer, type DataField, type DataFieldType, type EncryptedPayload, type EventType, type ExtendIdentityHandler, type ExtendIdentityRequest, type ExtendIdentityResponse, type ExtensionManifest, type ExtensionRegistryEntry, type FetchRequest, type FetchRequestInit, type FetchResponse, type HostToSandboxMessage, type IdentityBaseClaims, type IdentityEvent, type IdentityEventType, type IdentityState, type InstanceConfig, type InstanceOption, type InvokeAction, type MarketplaceExtension, type MessagingContext, type MessagingEvent, type MessagingEventHandler, type MessagingEventType, type MessagingPostbackEvent, type MessengerCommand, type NamedEntity, type Order, type OrderAction, type OrderItem, type OrderStatus, type OrderStatuses, PERMISSIONS, type Permission, type Price, RESERVED_CONTEXT_KEYS, type ReservedContextKey, type SandboxToHostMessage, type Shipment, type SurfaceContext, type SurfaceLifecycleMessage, type Target, type Theme, type ToastPayload, type UITag, type UITagCategory, UI_TAGS, UI_TAG_ATTRIBUTES, UI_TAG_ATTRIBUTE_VALUES, UI_TAG_CATEGORIES, UI_TAG_CHILDREN, UI_TAG_DEFINITIONS, type UserIdentity, type WidgetAction, tagToComponentName };
930
+ export { ALLOWED_ICONS, type ActionInvokePayload, type ActivityEvent, type ActivityEventHandler, type ActivityEventType, type Address, type AllowedIconName, type ApiError, type ApiRequest, type ApiResponse, CAPABILITY_PERMISSION_MAP, type CapabilityCall, type CapabilityRequest, type CapabilityResponse, type CapabilityType, type ContextData, type Customer, type DataField, type DataFieldType, type EncryptedPayload, type EventDomain, type EventType, type ExtendIdentityHandler, type ExtendIdentityRequest, type ExtendIdentityResponse, type ExtensionManifest, type ExtensionRegistryEntry, type FetchRequest, type FetchRequestInit, type FetchResponse, type HostToSandboxMessage, type IdentityBaseClaims, type IdentityEvent, type IdentityEventType, type IdentityState, type InstanceConfig, type InstanceOption, type InvokeAction, type MarketplaceExtension, type MessagingContext, type MessagingEvent, type MessagingEventHandler, type MessagingEventType, type MessagingPostbackEvent, type MessengerCommand, type NamedEntity, type Order, type OrderAction, type OrderItem, type OrderStatus, type OrderStatuses, PERMISSIONS, type Permission, type Price, RESERVED_CONTEXT_KEYS, type ReservedContextKey, type SandboxToHostMessage, type Shipment, type SurfaceContext, type SurfaceLifecycleMessage, type Target, type Theme, type ToastPayload, type UITag, type UITagCategory, UI_TAGS, UI_TAG_ATTRIBUTES, UI_TAG_ATTRIBUTE_VALUES, UI_TAG_CATEGORIES, UI_TAG_CHILDREN, UI_TAG_DEFINITIONS, type UserIdentity, type WellKnownActivityEvent, type WidgetAction, tagToComponentName };
package/dist/index.js CHANGED
@@ -1,3 +1,36 @@
1
+ // ../../../lib/contracts/src/base.ts
2
+ var asISOTimestamp = (value) => value;
3
+ var asClerkUserId = (value) => value;
4
+ var asClerkOrgId = (value) => value;
5
+
6
+ // ../../../lib/contracts/src/permissions.ts
7
+ var SUPER_ROLE = {
8
+ ADMIN: "org:super_admin"
9
+ };
10
+ var ORG_ROLE = {
11
+ ADMIN: "org:admin",
12
+ OWNER: "org:owner"};
13
+ var EDITOR_ROLES = [
14
+ SUPER_ROLE.ADMIN,
15
+ ORG_ROLE.ADMIN,
16
+ ORG_ROLE.OWNER
17
+ ];
18
+ [
19
+ ...Object.values(SUPER_ROLE),
20
+ ...Object.values(EDITOR_ROLES)
21
+ ];
22
+
23
+ // ../../../lib/contracts/src/marketplace.ts
24
+ var EXTENSION_CATEGORIES = [
25
+ "commerce",
26
+ "support",
27
+ "analytics",
28
+ "productivity",
29
+ "communication",
30
+ "other"
31
+ ];
32
+ var EXTENSION_VISIBILITIES = ["public", "protected"];
33
+
1
34
  // src/components.ts
2
35
  var UI_TAG_DEFINITIONS = {
3
36
  "ui-card": {
@@ -312,6 +345,7 @@ var PERMISSIONS = [
312
345
  "actions:invoke",
313
346
  "events:identity",
314
347
  "events:messaging",
348
+ "events:activity",
315
349
  "extend:identity"
316
350
  ];
317
351
  var CAPABILITY_PERMISSION_MAP = {
@@ -323,32 +357,4 @@ var CAPABILITY_PERMISSION_MAP = {
323
357
  "extend.identity": "extend:identity"
324
358
  };
325
359
 
326
- // ../../../lib/contracts/src/permissions.ts
327
- var SUPER_ROLE = {
328
- ADMIN: "org:super_admin"
329
- };
330
- var ORG_ROLE = {
331
- ADMIN: "org:admin",
332
- OWNER: "org:owner"};
333
- var EDITOR_ROLES = [
334
- SUPER_ROLE.ADMIN,
335
- ORG_ROLE.ADMIN,
336
- ORG_ROLE.OWNER
337
- ];
338
- [
339
- ...Object.values(SUPER_ROLE),
340
- ...Object.values(EDITOR_ROLES)
341
- ];
342
-
343
- // ../../../lib/contracts/src/marketplace.ts
344
- var EXTENSION_CATEGORIES = [
345
- "commerce",
346
- "support",
347
- "analytics",
348
- "productivity",
349
- "communication",
350
- "other"
351
- ];
352
- var EXTENSION_VISIBILITIES = ["public", "protected"];
353
-
354
- export { ALLOWED_ICONS, CAPABILITY_PERMISSION_MAP, EXTENSION_CATEGORIES, EXTENSION_VISIBILITIES, PERMISSIONS, RESERVED_CONTEXT_KEYS, UI_TAGS, UI_TAG_ATTRIBUTES, UI_TAG_ATTRIBUTE_VALUES, UI_TAG_CATEGORIES, UI_TAG_CHILDREN, UI_TAG_DEFINITIONS, tagToComponentName };
360
+ export { ALLOWED_ICONS, CAPABILITY_PERMISSION_MAP, EXTENSION_CATEGORIES, EXTENSION_VISIBILITIES, PERMISSIONS, RESERVED_CONTEXT_KEYS, UI_TAGS, UI_TAG_ATTRIBUTES, UI_TAG_ATTRIBUTE_VALUES, UI_TAG_CATEGORIES, UI_TAG_CHILDREN, UI_TAG_DEFINITIONS, asClerkOrgId, asClerkUserId, asISOTimestamp, tagToComponentName };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackable-labs/sdk-extension-contracts",
3
- "version": "1.69.2",
3
+ "version": "1.71.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",