@mochabug/adapt-sdk 0.1.1 → 0.1.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.
@@ -1,2 +1,2 @@
1
- "use strict";var a=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var c=(e,n)=>{for(var s in n)a(e,s,{get:n[s],enumerable:!0})},g=(e,n,s,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of h(n))!l.call(e,o)&&o!==s&&a(e,o,{get:()=>n[o],enumerable:!(t=r(n,o))||t.enumerable});return e};var f=e=>g(a({},"__esModule",{value:!0}),e);var u={};c(u,{getToken:()=>d});module.exports=f(u);async function d(e=!1){if(e)return"dev-token";if(typeof globalThis.window>"u"||typeof globalThis.location>"u")throw new Error("getToken() is only available in browser environments");let n=globalThis;return new Promise(s=>{let t=n.location.hash.substring(1);if(t){s(t);return}let o=()=>{let i=n.location.hash.substring(1);i&&(n.removeEventListener("hashchange",o),s(i))};n.addEventListener("hashchange",o)})}0&&(module.exports={getToken});
1
+ "use strict";var r=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var f=(o,n)=>{for(var e in n)r(o,e,{get:n[e],enumerable:!0})},d=(o,n,e,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of c(n))!w.call(o,t)&&t!==e&&r(o,t,{get:()=>n[t],enumerable:!(a=h(n,t))||a.enumerable});return o};var k=o=>d(r({},"__esModule",{value:!0}),o);var g={};f(g,{getToken:()=>b});module.exports=k(g);function b(o=!1){if(o)return"dev-token";let n="mb_token";if(typeof globalThis.window>"u"||typeof globalThis.location>"u")throw new Error("getToken() is only available in browser environments");let e=globalThis,a=e.location.hash.slice(1);if(!a)throw new Error("No token found in URL hash");let t=new URLSearchParams(a),s=t.get("mb_token");if(!s)throw new Error('Token "mb_token" not found in URL hash');t.delete(n);let i=t.toString(),l=e.location.pathname+e.location.search+(i?"#"+i:"");return e.history.replaceState(null,"",l),decodeURIComponent(s)}0&&(module.exports={getToken});
2
2
  //# sourceMappingURL=frontend.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/frontend.ts"],
4
- "sourcesContent": ["/**\n * Simple token utility for waiting on hash-based tokens\n */\n\n/**\n * Waits for a token to become available in the URL hash\n * @param isDevelopment - If true, resolves immediately with 'dev-token' for local development\n * @returns Promise that resolves with the token\n */\nexport async function getToken(isDevelopment = false): Promise<string> {\n // Development mode - return immediately\n if (isDevelopment) {\n return 'dev-token';\n }\n\n // Non-browser environment - throw error (using globalThis for universal compatibility)\n if (\n typeof (globalThis as any).window === 'undefined' ||\n typeof (globalThis as any).location === 'undefined'\n ) {\n throw new Error('getToken() is only available in browser environments');\n }\n\n // In browsers, globalThis is window, so we can use it directly\n const win = globalThis as any;\n\n return new Promise<string>((resolve) => {\n // Check if token already exists\n const currentToken = win.location.hash.substring(1);\n if (currentToken) {\n resolve(currentToken);\n return;\n }\n\n // Wait for hash change\n const handleHashChange = () => {\n const token = win.location.hash.substring(1);\n if (token) {\n win.removeEventListener('hashchange', handleHashChange);\n resolve(token);\n }\n };\n\n win.addEventListener('hashchange', handleHashChange);\n });\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GASA,eAAsBE,EAASE,EAAgB,GAAwB,CAErE,GAAIA,EACF,MAAO,YAIT,GACE,OAAQ,WAAmB,OAAW,KACtC,OAAQ,WAAmB,SAAa,IAExC,MAAM,IAAI,MAAM,sDAAsD,EAIxE,IAAMC,EAAM,WAEZ,OAAO,IAAI,QAAiBC,GAAY,CAEtC,IAAMC,EAAeF,EAAI,SAAS,KAAK,UAAU,CAAC,EAClD,GAAIE,EAAc,CAChBD,EAAQC,CAAY,EACpB,MACF,CAGA,IAAMC,EAAmB,IAAM,CAC7B,IAAMC,EAAQJ,EAAI,SAAS,KAAK,UAAU,CAAC,EACvCI,IACFJ,EAAI,oBAAoB,aAAcG,CAAgB,EACtDF,EAAQG,CAAK,EAEjB,EAEAJ,EAAI,iBAAiB,aAAcG,CAAgB,CACrD,CAAC,CACH",
6
- "names": ["frontend_exports", "__export", "getToken", "__toCommonJS", "isDevelopment", "win", "resolve", "currentToken", "handleHashChange", "token"]
4
+ "sourcesContent": ["/**\n * Simple token utility for waiting on hash-based tokens\n */\n\n/**\n * Waits for a token to become available in the URL hash\n * @param isDevelopment - If true, resolves immediately with 'dev-token' for local development\n * @returns Promise that resolves with the token\n */\nexport function getToken(isDevelopment = false): string {\n // Development mode - return immediately\n if (isDevelopment) {\n return 'dev-token';\n }\n\n const tokenKey = 'mb_token';\n\n // Non-browser environment - throw error (using globalThis for universal compatibility)\n if (\n typeof (globalThis as any).window === 'undefined' ||\n typeof (globalThis as any).location === 'undefined'\n ) {\n throw new Error('getToken() is only available in browser environments');\n }\n\n // In browsers, globalThis is window, so we can use it directly\n const win = globalThis as any;\n\n const hash = win.location.hash.slice(1); // Remove leading #\n if (!hash) {\n throw new Error('No token found in URL hash');\n }\n\n const params = new URLSearchParams(hash);\n const token = params.get('mb_token');\n if (!token) {\n throw new Error('Token \"mb_token\" not found in URL hash');\n }\n\n // Remove the key from hash and clean URL\n params.delete(tokenKey);\n const newHash = params.toString();\n const newUrl =\n win.location.pathname +\n win.location.search +\n (newHash ? '#' + newHash : '');\n win.history.replaceState(null, '', newUrl);\n\n return decodeURIComponent(token);\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GASO,SAASE,EAASE,EAAgB,GAAe,CAEtD,GAAIA,EACF,MAAO,YAGT,IAAMC,EAAW,WAGjB,GACE,OAAQ,WAAmB,OAAW,KACtC,OAAQ,WAAmB,SAAa,IAExC,MAAM,IAAI,MAAM,sDAAsD,EAIxE,IAAMC,EAAM,WAENC,EAAOD,EAAI,SAAS,KAAK,MAAM,CAAC,EACtC,GAAI,CAACC,EACH,MAAM,IAAI,MAAM,4BAA4B,EAG9C,IAAMC,EAAS,IAAI,gBAAgBD,CAAI,EACjCE,EAAQD,EAAO,IAAI,UAAU,EACnC,GAAI,CAACC,EACH,MAAM,IAAI,MAAM,wCAAwC,EAI1DD,EAAO,OAAOH,CAAQ,EACtB,IAAMK,EAAUF,EAAO,SAAS,EAC1BG,EACJL,EAAI,SAAS,SACbA,EAAI,SAAS,QACZI,EAAU,IAAMA,EAAU,IAC7B,OAAAJ,EAAI,QAAQ,aAAa,KAAM,GAAIK,CAAM,EAElC,mBAAmBF,CAAK,CACjC",
6
+ "names": ["frontend_exports", "__export", "getToken", "__toCommonJS", "isDevelopment", "tokenKey", "win", "hash", "params", "token", "newHash", "newUrl"]
7
7
  }
@@ -1,2 +1,2 @@
1
- async function i(a=!1){if(a)return"dev-token";if(typeof globalThis.window>"u"||typeof globalThis.location>"u")throw new Error("getToken() is only available in browser environments");let n=globalThis;return new Promise(e=>{let o=n.location.hash.substring(1);if(o){e(o);return}let s=()=>{let t=n.location.hash.substring(1);t&&(n.removeEventListener("hashchange",s),e(t))};n.addEventListener("hashchange",s)})}export{i as getToken};
1
+ function l(r=!1){if(r)return"dev-token";let s="mb_token";if(typeof globalThis.window>"u"||typeof globalThis.location>"u")throw new Error("getToken() is only available in browser environments");let n=globalThis,e=n.location.hash.slice(1);if(!e)throw new Error("No token found in URL hash");let o=new URLSearchParams(e),t=o.get("mb_token");if(!t)throw new Error('Token "mb_token" not found in URL hash');o.delete(s);let a=o.toString(),i=n.location.pathname+n.location.search+(a?"#"+a:"");return n.history.replaceState(null,"",i),decodeURIComponent(t)}export{l as getToken};
2
2
  //# sourceMappingURL=frontend.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/frontend.ts"],
4
- "sourcesContent": ["/**\n * Simple token utility for waiting on hash-based tokens\n */\n\n/**\n * Waits for a token to become available in the URL hash\n * @param isDevelopment - If true, resolves immediately with 'dev-token' for local development\n * @returns Promise that resolves with the token\n */\nexport async function getToken(isDevelopment = false): Promise<string> {\n // Development mode - return immediately\n if (isDevelopment) {\n return 'dev-token';\n }\n\n // Non-browser environment - throw error (using globalThis for universal compatibility)\n if (\n typeof (globalThis as any).window === 'undefined' ||\n typeof (globalThis as any).location === 'undefined'\n ) {\n throw new Error('getToken() is only available in browser environments');\n }\n\n // In browsers, globalThis is window, so we can use it directly\n const win = globalThis as any;\n\n return new Promise<string>((resolve) => {\n // Check if token already exists\n const currentToken = win.location.hash.substring(1);\n if (currentToken) {\n resolve(currentToken);\n return;\n }\n\n // Wait for hash change\n const handleHashChange = () => {\n const token = win.location.hash.substring(1);\n if (token) {\n win.removeEventListener('hashchange', handleHashChange);\n resolve(token);\n }\n };\n\n win.addEventListener('hashchange', handleHashChange);\n });\n}\n"],
5
- "mappings": "AASA,eAAsBA,EAASC,EAAgB,GAAwB,CAErE,GAAIA,EACF,MAAO,YAIT,GACE,OAAQ,WAAmB,OAAW,KACtC,OAAQ,WAAmB,SAAa,IAExC,MAAM,IAAI,MAAM,sDAAsD,EAIxE,IAAMC,EAAM,WAEZ,OAAO,IAAI,QAAiBC,GAAY,CAEtC,IAAMC,EAAeF,EAAI,SAAS,KAAK,UAAU,CAAC,EAClD,GAAIE,EAAc,CAChBD,EAAQC,CAAY,EACpB,MACF,CAGA,IAAMC,EAAmB,IAAM,CAC7B,IAAMC,EAAQJ,EAAI,SAAS,KAAK,UAAU,CAAC,EACvCI,IACFJ,EAAI,oBAAoB,aAAcG,CAAgB,EACtDF,EAAQG,CAAK,EAEjB,EAEAJ,EAAI,iBAAiB,aAAcG,CAAgB,CACrD,CAAC,CACH",
6
- "names": ["getToken", "isDevelopment", "win", "resolve", "currentToken", "handleHashChange", "token"]
4
+ "sourcesContent": ["/**\n * Simple token utility for waiting on hash-based tokens\n */\n\n/**\n * Waits for a token to become available in the URL hash\n * @param isDevelopment - If true, resolves immediately with 'dev-token' for local development\n * @returns Promise that resolves with the token\n */\nexport function getToken(isDevelopment = false): string {\n // Development mode - return immediately\n if (isDevelopment) {\n return 'dev-token';\n }\n\n const tokenKey = 'mb_token';\n\n // Non-browser environment - throw error (using globalThis for universal compatibility)\n if (\n typeof (globalThis as any).window === 'undefined' ||\n typeof (globalThis as any).location === 'undefined'\n ) {\n throw new Error('getToken() is only available in browser environments');\n }\n\n // In browsers, globalThis is window, so we can use it directly\n const win = globalThis as any;\n\n const hash = win.location.hash.slice(1); // Remove leading #\n if (!hash) {\n throw new Error('No token found in URL hash');\n }\n\n const params = new URLSearchParams(hash);\n const token = params.get('mb_token');\n if (!token) {\n throw new Error('Token \"mb_token\" not found in URL hash');\n }\n\n // Remove the key from hash and clean URL\n params.delete(tokenKey);\n const newHash = params.toString();\n const newUrl =\n win.location.pathname +\n win.location.search +\n (newHash ? '#' + newHash : '');\n win.history.replaceState(null, '', newUrl);\n\n return decodeURIComponent(token);\n}\n"],
5
+ "mappings": "AASO,SAASA,EAASC,EAAgB,GAAe,CAEtD,GAAIA,EACF,MAAO,YAGT,IAAMC,EAAW,WAGjB,GACE,OAAQ,WAAmB,OAAW,KACtC,OAAQ,WAAmB,SAAa,IAExC,MAAM,IAAI,MAAM,sDAAsD,EAIxE,IAAMC,EAAM,WAENC,EAAOD,EAAI,SAAS,KAAK,MAAM,CAAC,EACtC,GAAI,CAACC,EACH,MAAM,IAAI,MAAM,4BAA4B,EAG9C,IAAMC,EAAS,IAAI,gBAAgBD,CAAI,EACjCE,EAAQD,EAAO,IAAI,UAAU,EACnC,GAAI,CAACC,EACH,MAAM,IAAI,MAAM,wCAAwC,EAI1DD,EAAO,OAAOH,CAAQ,EACtB,IAAMK,EAAUF,EAAO,SAAS,EAC1BG,EACJL,EAAI,SAAS,SACbA,EAAI,SAAS,QACZI,EAAU,IAAMA,EAAU,IAC7B,OAAAJ,EAAI,QAAQ,aAAa,KAAM,GAAIK,CAAM,EAElC,mBAAmBF,CAAK,CACjC",
6
+ "names": ["getToken", "isDevelopment", "tokenKey", "win", "hash", "params", "token", "newHash", "newUrl"]
7
7
  }
@@ -6,5 +6,5 @@
6
6
  * @param isDevelopment - If true, resolves immediately with 'dev-token' for local development
7
7
  * @returns Promise that resolves with the token
8
8
  */
9
- export declare function getToken(isDevelopment?: boolean): Promise<string>;
9
+ export declare function getToken(isDevelopment?: boolean): string;
10
10
  //# sourceMappingURL=frontend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"frontend.d.ts","sourceRoot":"","sources":["../src/frontend.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,aAAa,UAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAoCrE"}
1
+ {"version":3,"file":"frontend.d.ts","sourceRoot":"","sources":["../src/frontend.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,aAAa,UAAQ,GAAG,MAAM,CAwCtD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mochabug/adapt-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "The API toolkit to facilitate mochabug adapt plugin development",
5
5
  "publishConfig": {
6
6
  "access": "public"