@whop/embedded-components-vanilla-js 1.0.0 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @whop/embedded-components-vanilla-js
2
2
 
3
+ ## 1.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - b282677: add messageDeleted event to ChatElement
8
+
9
+ ## 1.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 76d83c4: Add i18n translation support with 10 new locales (es, zh, nl, pt, de, it, fr, ja, pl, tr)
14
+
3
15
  ## 1.0.0
4
16
 
5
17
  ### Major Changes
@@ -1,4 +1,4 @@
1
- declare const locales: readonly ["en"];
1
+ declare const locales: readonly ["en", "es", "zh", "nl", "pt", "de", "it", "fr", "ja", "pl", "tr"];
2
2
  type I18nSupportedLocale = (typeof locales)[number];
3
3
 
4
4
  type CustomEventDetail<F> = F extends (ev: CustomEvent<infer D>) => void ? D : never;
@@ -325,6 +325,13 @@ interface ChatElementEvents {
325
325
  content: string;
326
326
  channelId: string;
327
327
  }>) => void;
328
+ /**
329
+ * Emitted when the user deletes a message.
330
+ * @param ev - The event containing the `id` in `ev.detail`.
331
+ */
332
+ messageDeleted: (ev: CustomEvent<{
333
+ id: string;
334
+ }>) => void;
328
335
  /**
329
336
  * Emitted when the user clicks on an experience mention.
330
337
  * @param ev - The event containing the `id` in `ev.detail`.
@@ -349,7 +356,7 @@ interface AttachmentClickEventAttachment {
349
356
  width?: number;
350
357
  height?: number;
351
358
  }
352
- declare const createTypedEvent$1: TypedEventCreatorFn<ChatElementEvents, "profileClick" | "linkClick" | "messageSent" | "experienceClick" | "attachmentClick">;
359
+ declare const createTypedEvent$1: TypedEventCreatorFn<ChatElementEvents, "profileClick" | "linkClick" | "messageSent" | "messageDeleted" | "experienceClick" | "attachmentClick">;
353
360
  type ChatElementEvent = InferEvent<typeof createTypedEvent$1>;
354
361
  /**
355
362
  * Configuration options for the ChatElement.
@@ -366,7 +373,7 @@ type ChatElementEvent = InferEvent<typeof createTypedEvent$1>;
366
373
  */
367
374
  interface ChatElementOptions {
368
375
  /**
369
- * The ID of the chat channel to connect to.
376
+ * The ID of the channel, DM, or support chat to connect to.
370
377
  */
371
378
  channelId: string;
372
379
  /**
@@ -481,6 +488,10 @@ interface ChatElementSnapshot {
481
488
  * console.log("Message sent:", ev.detail.id, ev.detail.content, ev.detail.channelId);
482
489
  * });
483
490
  *
491
+ * element.on("messageDeleted", (ev) => {
492
+ * console.log("Message deleted:", ev.detail.id);
493
+ * });
494
+ *
484
495
  * element.on("experienceClick", (ev) => {
485
496
  * console.log("Experience clicked:", ev.detail.id);
486
497
  * });
@@ -670,7 +681,7 @@ interface SearchElementOptions {
670
681
  */
671
682
  companyId?: string;
672
683
  /**
673
- * The ID of the chat channel to search messages in.
684
+ * The ID of the channel, DM, or support chat to search messages in.
674
685
  */
675
686
  channelId?: string;
676
687
  /**
@@ -709,7 +720,7 @@ interface SearchElementSnapshot {
709
720
  state: "loading" | "ready";
710
721
  }
711
722
  /**
712
- * A UI element that allows users to search for messages in a chat channel.
723
+ * A UI element that allows users to search for messages in a channel, DM, or support chat.
713
724
  *
714
725
  * @example Basic usage
715
726
  * ```typescript
@@ -3728,6 +3739,145 @@ interface PayoutsSession extends TypedEmitter<PayoutsSessionEvents> {
3728
3739
  showTreasuryBreakdownModal: <Force extends boolean = false>(options?: TreasuryBreakdownElementOptions | ((modal: ModalContainer) => TreasuryBreakdownElementOptions), force?: Force) => Force extends true ? ModalContainer : ModalContainer | undefined;
3729
3740
  }
3730
3741
 
3742
+ interface WalletSessionOptions {
3743
+ /**
3744
+ * The token to use for the session. If a function is provided, it will be called and awaited to get the token.
3745
+ * When a function is provided, the token will be refreshed automatically before it expires.
3746
+ *
3747
+ * if a string is provided, it will be used as the token and not refreshed automatically. However you can update the token at runtime by
3748
+ * calling `updateOptions` with a new token.
3749
+ *
3750
+ * For v1, mint this token from your backend with the existing `whop.accessTokens.create({ company_id })` call —
3751
+ * the same approach used by `PayoutsSession`. A dedicated `wallet:*` scope set is on the roadmap.
3752
+ *
3753
+ * @example
3754
+ * ```ts
3755
+ * // with a static token
3756
+ * async function createWalletSession() {
3757
+ * const token = await fetch("/api/token")
3758
+ * .then(res => res.json())
3759
+ * .then(data => data.token)
3760
+ * return whopElements.createWalletSession({ token, companyId })
3761
+ * }
3762
+ *
3763
+ * // with a dynamic function
3764
+ * function createWalletSession() {
3765
+ * return whopElements.createWalletSession({
3766
+ * companyId,
3767
+ * token: () => fetch("/api/token")
3768
+ * .then(res => res.json())
3769
+ * .then(data => data.token),
3770
+ * })
3771
+ * }
3772
+ * ```
3773
+ */
3774
+ token: Token | GetToken;
3775
+ /**
3776
+ * The company ID that owns the wallet.
3777
+ *
3778
+ * Accepts a `biz_*` ID. The wallet's underlying ledger account is resolved server-side from this value.
3779
+ * (A polymorphic `ledger_account_id` parameter is on the roadmap once `wallet:session:create` ships.)
3780
+ */
3781
+ companyId: string;
3782
+ /**
3783
+ * The currency to format display amounts in.
3784
+ *
3785
+ * @default "USD"
3786
+ */
3787
+ currency?: string;
3788
+ }
3789
+ interface ExpandedWalletSessionOptions extends WalletSessionOptions {
3790
+ }
3791
+ /**
3792
+ * Events emitted by the WalletSession.
3793
+ *
3794
+ * Listen to these events using the `on()` method.
3795
+ */
3796
+ interface WalletSessionEvents {
3797
+ /**
3798
+ * Emitted when the session options are updated via `updateOptions()`.
3799
+ * @param options - The updated options object
3800
+ */
3801
+ optionsUpdated: (options: ExpandedWalletSessionOptions) => void;
3802
+ /**
3803
+ * Emitted when the authentication token is refreshed.
3804
+ * @param token - The new token
3805
+ */
3806
+ tokenRefreshed: (token: string) => void;
3807
+ /**
3808
+ * Emitted when token refresh fails.
3809
+ * @param error - The error that occurred
3810
+ */
3811
+ tokenRefreshError: (error: unknown) => void;
3812
+ /**
3813
+ * Emitted when an error occurs during session operation.
3814
+ * @param error - The error that occurred
3815
+ */
3816
+ error: (error: unknown) => void;
3817
+ /**
3818
+ * Emitted when the session is ready and authenticated.
3819
+ */
3820
+ ready: () => void;
3821
+ }
3822
+ /**
3823
+ * Element registry for WalletSession.
3824
+ *
3825
+ * Empty for the foundation scaffold — wallet-element, send-element, onramp-element, convert-element
3826
+ * are added in follow-up PRs. Each entry is `[Options, ElementInstance]`.
3827
+ */
3828
+ type WalletSessionElements = {};
3829
+ /**
3830
+ * Manages authentication and creates wallet elements.
3831
+ *
3832
+ * The WalletSession handles token management, element creation, and provides
3833
+ * convenience methods for showing wallet elements in modals.
3834
+ *
3835
+ * For v1, mint the token via the existing `whop.accessTokens.create({ company_id })` flow —
3836
+ * the same backend mutation that powers `PayoutsSession`. No new mutation is required.
3837
+ *
3838
+ * @example Basic usage
3839
+ * ```typescript
3840
+ * const session = whopElements.createWalletSession({
3841
+ * companyId: "biz_xxx",
3842
+ * token: async () => {
3843
+ * const response = await fetch("/api/wallet-token");
3844
+ * const data = await response.json();
3845
+ * return data.token;
3846
+ * },
3847
+ * });
3848
+ *
3849
+ * session.on("ready", () => {
3850
+ * console.log("Wallet session is ready");
3851
+ * });
3852
+ * ```
3853
+ */
3854
+ interface WalletSession extends TypedEmitter<WalletSessionEvents> {
3855
+ /**
3856
+ * Update the session options after initialization.
3857
+ *
3858
+ * Changes will be propagated to all active elements.
3859
+ *
3860
+ * @param options - Partial options object with the values to update
3861
+ */
3862
+ updateOptions: (options: Partial<WalletSessionOptions>) => void;
3863
+ /**
3864
+ * Destroy the session and clean up all mounted elements.
3865
+ *
3866
+ * Call this when you no longer need the session to free up resources.
3867
+ */
3868
+ destroy: () => void;
3869
+ /**
3870
+ * Create a new element instance.
3871
+ *
3872
+ * @param type - The element type
3873
+ * @param options - Element-specific configuration options
3874
+ * @returns The created element instance
3875
+ */
3876
+ createElement<T extends keyof WalletSessionElements>(type: T | {
3877
+ type: T;
3878
+ }, options: WalletSessionElements[T] extends [infer O, unknown] ? O : never): WalletSessionElements[T] extends [unknown, infer E] ? E : never;
3879
+ }
3880
+
3731
3881
  declare global {
3732
3882
  interface Window {
3733
3883
  WhopElements: WhopElementsConstructor;
@@ -3849,6 +3999,16 @@ interface WhopElements extends TypedEmitter<WhopElementsEvents> {
3849
3999
  * @returns A ChatSession instance for creating chat elements
3850
4000
  */
3851
4001
  createChatSession: (options: ChatSessionOptions) => ChatSession;
4002
+ /**
4003
+ * Create a new wallet session for managing wallet elements.
4004
+ *
4005
+ * The session handles authentication and provides methods to create
4006
+ * wallet-related elements like balance displays, send/receive flows, and conversions.
4007
+ *
4008
+ * @param options - Configuration options for the wallet session
4009
+ * @returns A WalletSession instance for creating wallet elements
4010
+ */
4011
+ createWalletSession: (options: WalletSessionOptions) => WalletSession;
3852
4012
  /**
3853
4013
  * Update the WhopElements configuration after initialization.
3854
4014
  *
@@ -3876,4 +4036,4 @@ interface WhopElementsEvents {
3876
4036
  optionsUpdated: (options: WhopElementsOptions) => void;
3877
4037
  }
3878
4038
 
3879
- export { type AddPayoutMethodElement, type AddPayoutMethodElementOptions, type AddPayoutMethodElementSnapshot, type Appearance, type AutomaticWithdrawElement, type AutomaticWithdrawElementOptions, type AutomaticWithdrawElementSnapshot, type AvailableCashBreakdownElement, type AvailableCashBreakdownElementOptions, type AvailableCashBreakdownElementSnapshot, type BalanceElement, type BalanceElementOptions, type BalanceElementSnapshot, type BalancesElement, type BalancesElementOptions, type BalancesElementSnapshot, type ChangeAccountCountryElement, type ChangeAccountCountryElementOptions, type ChangeAccountCountryElementSnapshot, type ChatElement, type ChatElementEvent, type ChatElementOptions, type ChatElementSnapshot, type ChatSession, type ChatSessionElements, type ChatSessionEvents, type ChatSessionOptions, type DmsListElement, type DmsListElementEvent, type DmsListElementOptions, type DmsListElementSnapshot, type ExpandedChatSessionOptions, type ExpandedPayoutsSessionOptions, type GenerateWithdrawalReceiptElement, type GenerateWithdrawalReceiptElementOptions, type GenerateWithdrawalReceiptElementSnapshot, type I18nSupportedLocale, type PayoutsSession, type PayoutsSessionElements, type PayoutsSessionEvents, type PayoutsSessionOptions, type PendingBreakdownElement, type PendingBreakdownElementOptions, type PendingBreakdownElementSnapshot, type ReserveBreakdownElement, type ReserveBreakdownElementOptions, type ReserveBreakdownElementSnapshot, type ResetAccountElement, type ResetAccountElementOptions, type ResetAccountElementSnapshot, type SearchElement, type SearchElementOptions, type SearchElementSnapshot, type StatusBannerElement, type StatusBannerElementOptions, type StatusBannerElementSnapshot, type StatusBannerType, type TreasuryBreakdownElement, type TreasuryBreakdownElementOptions, type TreasuryBreakdownElementSnapshot, type VerifyElement, type VerifyElementOptions, type VerifyElementSnapshot, type WhopElement, WhopElementError, type WhopElementErrorCode, type WhopElements, type WhopElementsConstructor, type WhopElementsEnvironment, type WhopElementsEvents, type WhopElementsOptions, type WithdrawButtonElement, type WithdrawButtonElementOptions, type WithdrawElement, type WithdrawElementOptions, type WithdrawElementSnapshot, type WithdrawalBreakdownElement, type WithdrawalBreakdownElementOptions, type WithdrawalBreakdownElementSnapshot, type WithdrawalsElement, type WithdrawalsElementOptions, type WithdrawalsElementSnapshot };
4039
+ export { type AddPayoutMethodElement, type AddPayoutMethodElementOptions, type AddPayoutMethodElementSnapshot, type Appearance, type AutomaticWithdrawElement, type AutomaticWithdrawElementOptions, type AutomaticWithdrawElementSnapshot, type AvailableCashBreakdownElement, type AvailableCashBreakdownElementOptions, type AvailableCashBreakdownElementSnapshot, type BalanceElement, type BalanceElementOptions, type BalanceElementSnapshot, type BalancesElement, type BalancesElementOptions, type BalancesElementSnapshot, type ChangeAccountCountryElement, type ChangeAccountCountryElementOptions, type ChangeAccountCountryElementSnapshot, type ChatElement, type ChatElementEvent, type ChatElementOptions, type ChatElementSnapshot, type ChatSession, type ChatSessionElements, type ChatSessionEvents, type ChatSessionOptions, type DmsListElement, type DmsListElementEvent, type DmsListElementOptions, type DmsListElementSnapshot, type ExpandedChatSessionOptions, type ExpandedPayoutsSessionOptions, type ExpandedWalletSessionOptions, type GenerateWithdrawalReceiptElement, type GenerateWithdrawalReceiptElementOptions, type GenerateWithdrawalReceiptElementSnapshot, type I18nSupportedLocale, type PayoutsSession, type PayoutsSessionElements, type PayoutsSessionEvents, type PayoutsSessionOptions, type PendingBreakdownElement, type PendingBreakdownElementOptions, type PendingBreakdownElementSnapshot, type ReserveBreakdownElement, type ReserveBreakdownElementOptions, type ReserveBreakdownElementSnapshot, type ResetAccountElement, type ResetAccountElementOptions, type ResetAccountElementSnapshot, type SearchElement, type SearchElementOptions, type SearchElementSnapshot, type StatusBannerElement, type StatusBannerElementOptions, type StatusBannerElementSnapshot, type StatusBannerType, type TreasuryBreakdownElement, type TreasuryBreakdownElementOptions, type TreasuryBreakdownElementSnapshot, type VerifyElement, type VerifyElementOptions, type VerifyElementSnapshot, type WalletSession, type WalletSessionElements, type WalletSessionEvents, type WalletSessionOptions, type WhopElement, WhopElementError, type WhopElementErrorCode, type WhopElements, type WhopElementsConstructor, type WhopElementsEnvironment, type WhopElementsEvents, type WhopElementsOptions, type WithdrawButtonElement, type WithdrawButtonElementOptions, type WithdrawElement, type WithdrawElementOptions, type WithdrawElementSnapshot, type WithdrawalBreakdownElement, type WithdrawalBreakdownElementOptions, type WithdrawalBreakdownElementSnapshot, type WithdrawalsElement, type WithdrawalsElementOptions, type WithdrawalsElementSnapshot };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whop/embedded-components-vanilla-js",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Whop Elements loading utility",
5
5
  "keywords": [
6
6
  "Elements",