whop 1.0.4 → 1.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c6ea2caf5959059d7e27c54eecb479e8007420a1e3989fcc8ab9b3cf3d6be4e
4
- data.tar.gz: 9f2d86766b0cd27d265e9fd87c1be3102b9baf0c9d836539d4217427d864e998
3
+ metadata.gz: ba25e2187ff6be4ded65c7b7a17cc1d3ab7d450a962929fbc4f487042f51481e
4
+ data.tar.gz: 88877e474fc48d922a48f0876b2c754f2dcc7cae7ee1b81bc44ad3a233ba16ec
5
5
  SHA512:
6
- metadata.gz: 7e08a3e8c6bc48cad71cfc3bd5c7e67feb0718df8077bbdbbbd046d24de8e27e5a29e60b8c37a9c30a82952ba11c15a21708e215f62fff670a1bff4a3881054d
7
- data.tar.gz: f9697d3d60918f218c6bc61798733cc83bc7d46b4a6e679042e7434c39c5d84d8ec3d0d16f623603ebe9ae32ddb05993f7a0e52f6210adb5f16259823341ad6e
6
+ metadata.gz: 7ac76a99d56ef1a6555d9d07b44470a0f0811ae0729b57b56762c99ef435c06489bc0504787dfe4f18b1af83bf6d9942337f9e26cf24f5538e31e3d731e9e328
7
+ data.tar.gz: b67aad3ba1659706a4ba9a09c94c998bd78569ff577f8b208d5f76265e4c0617142a88de68a3a7ebedb313f06164e7e2329f703996caaa300f450a9f64e48a22
data/README.md CHANGED
@@ -118,13 +118,18 @@ curl -i -X POST http://localhost:3000/whop/webhooks \
118
118
  ## Using the client
119
119
  # Frontend (iframe) helper
120
120
 
121
- Add the SDK tags in your layout head:
121
+ Add the SDK tags in your layout head (includes UMD + ESM fallback and turbo:load re-init):
122
122
 
123
123
  ```erb
124
124
  <%= extend(Whop::IframeHelper) && whop_iframe_sdk_tags %>
125
125
  ```
126
126
 
127
127
  Ensure your CSP allows Whop domains; the installer adds `config/initializers/whop_iframe.rb` with sensible defaults (script/connect/frame to unpkg.com, esm.sh, whop.com/*).
128
+ If you prefer not to expose `WHOP_APP_ID` to the layout, add it to body:
129
+
130
+ ```erb
131
+ <body data-whop-app-id="<%= ENV['WHOP_APP_ID'] %>">
132
+ ```
128
133
 
129
134
 
130
135
  ```ruby
@@ -44,7 +44,32 @@ module Whop
44
44
  })();
45
45
  JS
46
46
 
47
- html = %Q(<script src="https://unpkg.com/@whop/iframe@latest"#{nonce_attr}></script>\n<script#{nonce_attr}>#{init.strip}</script>)
47
+ # ESM fallback: if iframeSdk wasn't created by UMD, import from esm.sh and init on DOM load and Turbo
48
+ module_bootstrap = <<~JS
49
+ (function(){
50
+ function _init() {
51
+ try {
52
+ if (window.iframeSdk) return;
53
+ var appId = document.body && document.body.dataset && document.body.dataset.whopAppId || #{resolved_app_id.to_s.strip.empty? ? '""' : ERB::Util.html_escape(resolved_app_id).inspect};
54
+ if (!appId) return;
55
+ import("https://esm.sh/@whop/iframe@latest").then(function(mod){
56
+ var create = mod && (mod.createSdk || mod.default && mod.default.createSdk);
57
+ if (typeof create === "function" && !window.iframeSdk) {
58
+ window.iframeSdk = create({ appId: appId });
59
+ }
60
+ }).catch(function(){});
61
+ } catch(e) {}
62
+ }
63
+ if (document.readyState === "loading") {
64
+ document.addEventListener("DOMContentLoaded", _init);
65
+ } else {
66
+ _init();
67
+ }
68
+ window.addEventListener && window.addEventListener("turbo:load", _init);
69
+ })();
70
+ JS
71
+
72
+ html = %Q(<script src="https://unpkg.com/@whop/iframe@latest"#{nonce_attr}></script>\n<script#{nonce_attr}>#{init.strip}</script>\n<script type="module"#{nonce_attr}>#{module_bootstrap.strip}</script>)
48
73
  html.respond_to?(:html_safe) ? html.html_safe : html
49
74
  end
50
75
  end
data/lib/whop/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Whop
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
4
4
 
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikhil Nelson