@planningcenter/url 3.2.0-qa-60.1 → 3.2.0-qa-60.2

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/url.js CHANGED
@@ -1,2 +1,2 @@
1
- var n=function(n){return function(t){if(n&&t){var e=function(){return"undefined"!=typeof location&&location&&location.protocol&&"https:"===location.protocol?"https":"http"};switch(n){case"production":return"https://"+t+"."+c();case"staging":return"https://"+t+"-staging."+c();case"testing":return"https://"+t+"-testing."+c();case"development":var r="test";try{r=location.hostname.match(/\pco\.(\w+)$/)[1]}catch(n){"localhost"!==location.hostname&&console.error(location.hostname+" is not a supported dev TLD")}var a=i(t);return e()+"://"+(a?a+".":"")+t+".pco."+r;case"prototype":return"https://"+o()+"."+t+".planningcenter.ninja";case"test":var s=i(t);return e()+"://"+(s?s+".":"")+t+".pco.test";default:return"http://"+t+"."+c()}}}},t=function(n){return"staging"===n&&"testing"===e()?"testing":n},e=function(){var n=window.location.origin;return n.endsWith("-testing.planningcenteronline.com")||n.endsWith("/testing.planningcenteronline.com")||n.endsWith(".testing.churchcenter.com")||n.endsWith("/testing.churchcenter.com")?"testing":n.endsWith("-staging.planningcenteronline.com")||n.endsWith("/staging.planningcenteronline.com")||n.endsWith(".staging.churchcenter.com")||n.endsWith("/staging.churchcenter.com")?"staging":n.endsWith(".planningcenteronline.com")||n.endsWith(".churchcenter.com")||n.endsWith("/churchcenter.com")?"production":n.endsWith(".planningcenter.ninja")||n.endsWith(".churchcenter.ninja")?"prototype":n.endsWith("pco.codes")||n.endsWith("pco.dev")||n.endsWith("pco.test")||n.endsWith("churchcenter.test")?"development":"production"},o=function(){var n,t,e=null==(n=location)||null==(t=n.hostname)?void 0:t.match(/(?:www\.)?(.+)\..+\.planningcenter\.ninja/);return e&&"localhost"!==e[1]?e[1]:"main"},i=function(n){var t,e,o=null==(t=location)||null==(e=t.hostname)?void 0:e.match(/^(.+?)\.(.+?)\.pco\.\w+$/);return o&&o[2]===n?o[1]:null},c=function(){var n=location.hostname.match(/planningcenter(online)?.com/);return null===n?"planningcenteronline.com":n[0]};exports.default=n,exports.inferEnvironment=e,exports.pcoApiUrl=function(o,i){var c=void 0===i?{}:i,r=c.env,a=void 0===r?e():r,s=c.squiggly,l=void 0===s||s;a=t(a);var h,p,u=l?"/~api":"";return u+="/"+o+"/v2",n(a)(l?(void 0===h&&(h=1),(p=window.location.hostname.split(".").slice(0,-1*(1+h)))["prototype"===e()?p.length-1:0].replace(/-staging$/,"").replace(/-testing$/,"")):"api")+u},exports.pcoUrl=function(o,i){var c=(void 0===i?{}:i).env,r=void 0===c?e():c;return r=t(r),n(r)(o)};
1
+ var n=function(n){return function(e){if((n=t(n))&&e){var r=function(){return"undefined"!=typeof location&&location&&location.protocol&&"https:"===location.protocol?"https":"http"};switch(n){case"production":return"https://"+e+"."+c();case"staging":return"https://"+e+"-staging."+c();case"testing":return"https://"+e+"-testing."+c();case"development":var a="test";try{a=location.hostname.match(/\pco\.(\w+)$/)[1]}catch(n){"localhost"!==location.hostname&&console.error(location.hostname+" is not a supported dev TLD")}var s=i(e);return r()+"://"+(s?s+".":"")+e+".pco."+a;case"prototype":return"https://"+o()+"."+e+".planningcenter.ninja";case"test":var l=i(e);return r()+"://"+(l?l+".":"")+e+".pco.test";default:return"http://"+e+"."+c()}}}},t=function(n){return"staging"===n&&"testing"===e()?"testing":n},e=function(){var n=window.location.origin;return n.endsWith("-testing.planningcenteronline.com")||n.endsWith("/testing.planningcenteronline.com")||n.endsWith(".testing.churchcenter.com")||n.endsWith("/testing.churchcenter.com")?"testing":n.endsWith("-staging.planningcenteronline.com")||n.endsWith("/staging.planningcenteronline.com")||n.endsWith(".staging.churchcenter.com")||n.endsWith("/staging.churchcenter.com")?"staging":n.endsWith(".planningcenteronline.com")||n.endsWith(".churchcenter.com")||n.endsWith("/churchcenter.com")?"production":n.endsWith(".planningcenter.ninja")||n.endsWith(".churchcenter.ninja")?"prototype":n.endsWith("pco.codes")||n.endsWith("pco.dev")||n.endsWith("pco.test")||n.endsWith("churchcenter.test")?"development":"production"},o=function(){var n,t,e=null==(n=location)||null==(t=n.hostname)?void 0:t.match(/(?:www\.)?(.+)\..+\.planningcenter\.ninja/);return e&&"localhost"!==e[1]?e[1]:"main"},i=function(n){var t,e,o=null==(t=location)||null==(e=t.hostname)?void 0:e.match(/^(.+?)\.(.+?)\.pco\.\w+$/);return o&&o[2]===n?o[1]:null},c=function(){var n=location.hostname.match(/planningcenter(online)?.com/);return null===n?"planningcenteronline.com":n[0]};exports.default=n,exports.inferEnvironment=e,exports.pcoApiUrl=function(t,o){var i,c,r=void 0===o?{}:o,a=r.env,s=void 0===a?e():a,l=r.squiggly,h=void 0===l||l,p=h?"/~api":"";return p+="/"+t+"/v2",n(s)(h?(void 0===i&&(i=1),(c=window.location.hostname.split(".").slice(0,-1*(1+i)))["prototype"===e()?c.length-1:0].replace(/-staging$/,"").replace(/-testing$/,"")):"api")+p},exports.pcoUrl=function(t,o){var i=(void 0===o?{}:o).env,c=void 0===i?e():i;return n(c)(t)};
2
2
  //# sourceMappingURL=url.js.map
package/dist/url.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"url.js","sources":["../index.ts"],"sourcesContent":["export type Environment =\n | \"production\"\n | \"staging\"\n | \"testing\"\n | \"development\"\n | \"test\"\n | \"prototype\"\n\nexport type Product =\n | \"api\"\n | \"accounts\"\n | \"calendar\"\n | \"check-ins\"\n | \"giving\"\n | \"groups\"\n | \"home\"\n | \"login\"\n | \"people\"\n | \"publishing\"\n | \"registrations\"\n | \"services\"\n\nconst legacy = (env: Environment) => (productName: Product) => {\n if (!(env && productName)) return\n\n const getCurrentProtocol = () => {\n if (typeof location !== 'undefined' && location && location.protocol) {\n return location.protocol === 'https:' ? 'https' : 'http'\n }\n return 'http'\n }\n\n switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${domain()}`\n case \"testing\":\n return `https://${productName}-testing.${domain()}`\n case \"development\": {\n let tld = \"test\"\n\n try {\n tld = location.hostname.match(/\\pco\\.(\\w+)$/)[1]\n } catch (error) {\n // don't show warning in Topbar's local dev env\n if (location.hostname !== \"localhost\") {\n console.error(`${location.hostname} is not a supported dev TLD`)\n }\n }\n\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.${tld}`\n }\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\": {\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.test`\n }\n default:\n return `http://${productName}.${domain()}`\n }\n}\n\nexport default legacy\n\nexport function pcoUrl(\n product: Product,\n { env = inferEnvironment() }: { env?: Environment } = {},\n) {\n env = resolveEnvironment(env)\n return legacy(env)(product)\n}\n\nexport function pcoApiUrl(\n product: Product,\n {\n env = inferEnvironment(),\n squiggly = true,\n }: { env?: Environment; squiggly?: boolean } = {},\n) {\n env = resolveEnvironment(env)\n let path = squiggly ? \"/~api\" : \"\"\n path += `/${product}/v2`\n\n return legacy(env)(squiggly ? inferProduct() : \"api\") + path\n}\n\nconst resolveEnvironment = (env: Environment): Environment => {\n if (env === \"staging\" && inferEnvironment() === \"testing\") return \"testing\"\n return env\n}\n\nexport const inferEnvironment = () => {\n const origin = window.location.origin\n\n if (origin.endsWith(\"-testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\".testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"-staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\".staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\".planningcenteronline.com\")) return \"production\"\n if (origin.endsWith(\".churchcenter.com\")) return \"production\"\n if (origin.endsWith(\"/churchcenter.com\")) return \"production\"\n if (origin.endsWith(\".planningcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\".churchcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\"pco.codes\")) return \"development\"\n if (origin.endsWith(\"pco.dev\")) return \"development\"\n if (origin.endsWith(\"pco.test\")) return \"development\"\n if (origin.endsWith(\"churchcenter.test\")) return \"development\"\n\n return \"production\"\n}\n/**\n * If the hostname is a Protonova URL, get the env from the subdomain. Defaults to main.\n * Example: my-cool-change.accounts.planningcenter.ninja -> my-cool-change\n * @returns {string}\n */\nconst prototypeEnv = () => {\n const result = location?.hostname?.match(\n /(?:www\\.)?(.+)\\..+\\.planningcenter\\.ninja/,\n )\n\n if (result && result[1] !== \"localhost\") {\n return result[1]\n }\n\n return \"main\"\n}\n\nconst worktreeName = (productName: string) => {\n const match = location?.hostname?.match(/^(.+?)\\.(.+?)\\.pco\\.\\w+$/)\n if (match && match[2] === productName) return match[1]\n return null\n}\n\nconst domain = () => {\n const result = location.hostname.match(/planningcenter(online)?.com/)\n\n if (result === null) {\n return \"planningcenteronline.com\"\n } else {\n return result[0]\n }\n}\n\nconst extractSubdomainsFrom = (host, tldLength = 1) => {\n return host.split(\".\").slice(0, (1 + tldLength) * -1)\n}\n\nconst inferProduct = () => {\n const subdomains = extractSubdomainsFrom(window.location.hostname)\n\n return subdomains[\n inferEnvironment() === \"prototype\" ? subdomains.length - 1 : 0\n ].replace(/-staging$/, \"\").replace(/-testing$/, \"\")\n}\n"],"names":["legacy","env","productName","getCurrentProtocol","location","protocol","domain","tld","hostname","match","error","console","prefix","worktreeName","prototypeEnv","resolveEnvironment","inferEnvironment","origin","window","endsWith","_location","_location$hostname","result","_location2","_location2$hostname","pcoApiUrl","product","_ref2","_temp2","squiggly","_ref2$squiggly","tldLength","subdomains","path","split","slice","length","replace","_temp","_ref$env"],"mappings":"AAsBMA,IAAAA,EAAS,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| \"testing\"\n | \"development\"\n | \"test\"\n | \"prototype\"\n\nexport type Product =\n | \"api\"\n | \"accounts\"\n | \"calendar\"\n | \"check-ins\"\n | \"giving\"\n | \"groups\"\n | \"home\"\n | \"login\"\n | \"people\"\n | \"publishing\"\n | \"registrations\"\n | \"services\"\n\nconst legacy = (env: Environment) => (productName: Product) => {\n env = resolveEnvironment(env)\n if (!(env && productName)) return\n\n const getCurrentProtocol = () => {\n if (typeof location !== 'undefined' && location && location.protocol) {\n return location.protocol === 'https:' ? 'https' : 'http'\n }\n return 'http'\n }\n\n switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${domain()}`\n case \"testing\":\n return `https://${productName}-testing.${domain()}`\n case \"development\": {\n let tld = \"test\"\n\n try {\n tld = location.hostname.match(/\\pco\\.(\\w+)$/)[1]\n } catch (error) {\n // don't show warning in Topbar's local dev env\n if (location.hostname !== \"localhost\") {\n console.error(`${location.hostname} is not a supported dev TLD`)\n }\n }\n\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.${tld}`\n }\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\": {\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.test`\n }\n default:\n return `http://${productName}.${domain()}`\n }\n}\n\nexport default legacy\n\nexport function pcoUrl(\n product: Product,\n { env = inferEnvironment() }: { env?: Environment } = {},\n) {\n return legacy(env)(product)\n}\n\nexport function pcoApiUrl(\n product: Product,\n {\n env = inferEnvironment(),\n squiggly = true,\n }: { env?: Environment; squiggly?: boolean } = {},\n) {\n let path = squiggly ? \"/~api\" : \"\"\n path += `/${product}/v2`\n\n return legacy(env)(squiggly ? inferProduct() : \"api\") + path\n}\n\nconst resolveEnvironment = (env: Environment): Environment => {\n if (env === \"staging\" && inferEnvironment() === \"testing\") return \"testing\"\n return env\n}\n\nexport const inferEnvironment = () => {\n const origin = window.location.origin\n\n if (origin.endsWith(\"-testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\".testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"-staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\".staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\".planningcenteronline.com\")) return \"production\"\n if (origin.endsWith(\".churchcenter.com\")) return \"production\"\n if (origin.endsWith(\"/churchcenter.com\")) return \"production\"\n if (origin.endsWith(\".planningcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\".churchcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\"pco.codes\")) return \"development\"\n if (origin.endsWith(\"pco.dev\")) return \"development\"\n if (origin.endsWith(\"pco.test\")) return \"development\"\n if (origin.endsWith(\"churchcenter.test\")) return \"development\"\n\n return \"production\"\n}\n/**\n * If the hostname is a Protonova URL, get the env from the subdomain. Defaults to main.\n * Example: my-cool-change.accounts.planningcenter.ninja -> my-cool-change\n * @returns {string}\n */\nconst prototypeEnv = () => {\n const result = location?.hostname?.match(\n /(?:www\\.)?(.+)\\..+\\.planningcenter\\.ninja/,\n )\n\n if (result && result[1] !== \"localhost\") {\n return result[1]\n }\n\n return \"main\"\n}\n\nconst worktreeName = (productName: string) => {\n const match = location?.hostname?.match(/^(.+?)\\.(.+?)\\.pco\\.\\w+$/)\n if (match && match[2] === productName) return match[1]\n return null\n}\n\nconst domain = () => {\n const result = location.hostname.match(/planningcenter(online)?.com/)\n\n if (result === null) {\n return \"planningcenteronline.com\"\n } else {\n return result[0]\n }\n}\n\nconst extractSubdomainsFrom = (host, tldLength = 1) => {\n return host.split(\".\").slice(0, (1 + tldLength) * -1)\n}\n\nconst inferProduct = () => {\n const subdomains = extractSubdomainsFrom(window.location.hostname)\n\n return subdomains[\n inferEnvironment() === \"prototype\" ? subdomains.length - 1 : 0\n ].replace(/-staging$/, \"\").replace(/-testing$/, \"\")\n}\n"],"names":["legacy","env","productName","resolveEnvironment","getCurrentProtocol","location","protocol","domain","tld","hostname","match","error","console","prefix","worktreeName","prototypeEnv","inferEnvironment","origin","window","endsWith","result","_location","_location$hostname","_location2","_location2$hostname","product","_temp2","tldLength","subdomains","_ref2$env","_ref2","squiggly","_ref2$squiggly","path","split","slice","length","replace","_temp","_ref$env"],"mappings":"AAsBMA,IAAAA,EAAS,SAACC,GAAqB,OAAA,SAACC,GAEpC,IADAD,EAAME,EAAmBF,KACZC,EAAb,CAEA,IAAME,EAAqB,WACzB,MAAwB,oBAAbC,UAA4BA,UAAYA,SAASC,UAC7B,WAAtBD,SAASC,SAAwB,QAEnC,MACR,EAED,OAAQL,GACN,IAAK,aACH,iBAAkBC,EAAlB,IAAiCK,IACnC,IAAK,UACH,iBAAkBL,EAAlB,YAAyCK,IAC3C,IAAK,UACH,iBAAkBL,EAAlB,YAAyCK,IAC3C,IAAK,cACH,IAAIC,EAAM,OAEV,IACEA,EAAMH,SAASI,SAASC,MAAM,gBAAgB,EAM/C,CALC,MAAOC,GAEmB,cAAtBN,SAASI,UACXG,QAAQD,MAASN,SAASI,SAA1B,8BAEH,CAED,IAAMI,EAASC,EAAaZ,GAC5B,OAAUE,WAA0BS,EAAYA,EAAY,IAAA,IAAKX,EAAjE,QAAoFM,EAEtF,IAAK,YACH,MAAA,WAAkBO,IAAlB,IAAoCb,EACtC,wBAAA,IAAK,OACH,IAAMW,EAASC,EAAaZ,GAC5B,OAAUE,IAA0BS,OAAAA,EAAYA,EAAN,IAAkB,IAAKX,cAEnE,QACE,gBAAiBA,EAAjB,IAAgCK,IAtCT,CAwC5B,CA1Cc,EAkETJ,EAAqB,SAACF,GAC1B,MAAY,YAARA,GAA4C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GAC7DC,QAAQ,YAAa,IAAIA,QAAQ,YAAa,KAzED,OAASJ,CACzD,0BAjBCR,EADIa,OAEoDC,cAAF,CAAA,EAAED,GAAtDrC,IAAAA,aAAMe,MAER,OAAOhB,EAAOC,EAAPD,CAAYyB,EACpB"}
@@ -1,2 +1,2 @@
1
- const n=n=>t=>{if(!n||!t)return;const e=()=>"undefined"!=typeof location&&location&&location.protocol&&"https:"===location.protocol?"https":"http";switch(n){case"production":return`https://${t}.${r()}`;case"staging":return`https://${t}-staging.${r()}`;case"testing":return`https://${t}-testing.${r()}`;case"development":{let n="test";try{n=location.hostname.match(/\pco\.(\w+)$/)[1]}catch(n){"localhost"!==location.hostname&&console.error(`${location.hostname} is not a supported dev TLD`)}const o=s(t);return`${e()}://${o?`${o}.`:""}${t}.pco.${n}`}case"prototype":return`https://${i()}.${t}.planningcenter.ninja`;case"test":{const n=s(t);return`${e()}://${n?`${n}.`:""}${t}.pco.test`}default:return`http://${t}.${r()}`}};function t(t,{env:e=c()}={}){return e=o(e),n(e)(t)}function e(t,{env:e=c(),squiggly:i=!0}={}){e=o(e);let s=i?"/~api":"";return s+=`/${t}/v2`,n(e)(i?a():"api")+s}const o=n=>"staging"===n&&"testing"===c()?"testing":n,c=()=>{const n=window.location.origin;return n.endsWith("-testing.planningcenteronline.com")||n.endsWith("/testing.planningcenteronline.com")||n.endsWith(".testing.churchcenter.com")||n.endsWith("/testing.churchcenter.com")?"testing":n.endsWith("-staging.planningcenteronline.com")||n.endsWith("/staging.planningcenteronline.com")||n.endsWith(".staging.churchcenter.com")||n.endsWith("/staging.churchcenter.com")?"staging":n.endsWith(".planningcenteronline.com")||n.endsWith(".churchcenter.com")||n.endsWith("/churchcenter.com")?"production":n.endsWith(".planningcenter.ninja")||n.endsWith(".churchcenter.ninja")?"prototype":n.endsWith("pco.codes")||n.endsWith("pco.dev")||n.endsWith("pco.test")||n.endsWith("churchcenter.test")?"development":"production"},i=()=>{var n,t;const e=null==(n=location)||null==(t=n.hostname)?void 0:t.match(/(?:www\.)?(.+)\..+\.planningcenter\.ninja/);return e&&"localhost"!==e[1]?e[1]:"main"},s=n=>{var t,e;const o=null==(t=location)||null==(e=t.hostname)?void 0:e.match(/^(.+?)\.(.+?)\.pco\.\w+$/);return o&&o[2]===n?o[1]:null},r=()=>{const n=location.hostname.match(/planningcenter(online)?.com/);return null===n?"planningcenteronline.com":n[0]},a=()=>{const n=((n,t=1)=>window.location.hostname.split(".").slice(0,-1*(1+t)))();return n["prototype"===c()?n.length-1:0].replace(/-staging$/,"").replace(/-testing$/,"")};export{n as default,c as inferEnvironment,e as pcoApiUrl,t as pcoUrl};
1
+ const n=n=>t=>{if(!(n=o(n))||!t)return;const e=()=>"undefined"!=typeof location&&location&&location.protocol&&"https:"===location.protocol?"https":"http";switch(n){case"production":return`https://${t}.${r()}`;case"staging":return`https://${t}-staging.${r()}`;case"testing":return`https://${t}-testing.${r()}`;case"development":{let n="test";try{n=location.hostname.match(/\pco\.(\w+)$/)[1]}catch(n){"localhost"!==location.hostname&&console.error(`${location.hostname} is not a supported dev TLD`)}const o=s(t);return`${e()}://${o?`${o}.`:""}${t}.pco.${n}`}case"prototype":return`https://${i()}.${t}.planningcenter.ninja`;case"test":{const n=s(t);return`${e()}://${n?`${n}.`:""}${t}.pco.test`}default:return`http://${t}.${r()}`}};function t(t,{env:e=c()}={}){return n(e)(t)}function e(t,{env:e=c(),squiggly:o=!0}={}){let i=o?"/~api":"";return i+=`/${t}/v2`,n(e)(o?a():"api")+i}const o=n=>"staging"===n&&"testing"===c()?"testing":n,c=()=>{const n=window.location.origin;return n.endsWith("-testing.planningcenteronline.com")||n.endsWith("/testing.planningcenteronline.com")||n.endsWith(".testing.churchcenter.com")||n.endsWith("/testing.churchcenter.com")?"testing":n.endsWith("-staging.planningcenteronline.com")||n.endsWith("/staging.planningcenteronline.com")||n.endsWith(".staging.churchcenter.com")||n.endsWith("/staging.churchcenter.com")?"staging":n.endsWith(".planningcenteronline.com")||n.endsWith(".churchcenter.com")||n.endsWith("/churchcenter.com")?"production":n.endsWith(".planningcenter.ninja")||n.endsWith(".churchcenter.ninja")?"prototype":n.endsWith("pco.codes")||n.endsWith("pco.dev")||n.endsWith("pco.test")||n.endsWith("churchcenter.test")?"development":"production"},i=()=>{var n,t;const e=null==(n=location)||null==(t=n.hostname)?void 0:t.match(/(?:www\.)?(.+)\..+\.planningcenter\.ninja/);return e&&"localhost"!==e[1]?e[1]:"main"},s=n=>{var t,e;const o=null==(t=location)||null==(e=t.hostname)?void 0:e.match(/^(.+?)\.(.+?)\.pco\.\w+$/);return o&&o[2]===n?o[1]:null},r=()=>{const n=location.hostname.match(/planningcenter(online)?.com/);return null===n?"planningcenteronline.com":n[0]},a=()=>{const n=((n,t=1)=>window.location.hostname.split(".").slice(0,-1*(1+t)))();return n["prototype"===c()?n.length-1:0].replace(/-staging$/,"").replace(/-testing$/,"")};export{n as default,c as inferEnvironment,e as pcoApiUrl,t as pcoUrl};
2
2
  //# sourceMappingURL=url.modern.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"url.modern.js","sources":["../index.ts"],"sourcesContent":["export type Environment =\n | \"production\"\n | \"staging\"\n | \"testing\"\n | \"development\"\n | \"test\"\n | \"prototype\"\n\nexport type Product =\n | \"api\"\n | \"accounts\"\n | \"calendar\"\n | \"check-ins\"\n | \"giving\"\n | \"groups\"\n | \"home\"\n | \"login\"\n | \"people\"\n | \"publishing\"\n | \"registrations\"\n | \"services\"\n\nconst legacy = (env: Environment) => (productName: Product) => {\n if (!(env && productName)) return\n\n const getCurrentProtocol = () => {\n if (typeof location !== 'undefined' && location && location.protocol) {\n return location.protocol === 'https:' ? 'https' : 'http'\n }\n return 'http'\n }\n\n switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${domain()}`\n case \"testing\":\n return `https://${productName}-testing.${domain()}`\n case \"development\": {\n let tld = \"test\"\n\n try {\n tld = location.hostname.match(/\\pco\\.(\\w+)$/)[1]\n } catch (error) {\n // don't show warning in Topbar's local dev env\n if (location.hostname !== \"localhost\") {\n console.error(`${location.hostname} is not a supported dev TLD`)\n }\n }\n\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.${tld}`\n }\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\": {\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.test`\n }\n default:\n return `http://${productName}.${domain()}`\n }\n}\n\nexport default legacy\n\nexport function pcoUrl(\n product: Product,\n { env = inferEnvironment() }: { env?: Environment } = {},\n) {\n env = resolveEnvironment(env)\n return legacy(env)(product)\n}\n\nexport function pcoApiUrl(\n product: Product,\n {\n env = inferEnvironment(),\n squiggly = true,\n }: { env?: Environment; squiggly?: boolean } = {},\n) {\n env = resolveEnvironment(env)\n let path = squiggly ? \"/~api\" : \"\"\n path += `/${product}/v2`\n\n return legacy(env)(squiggly ? inferProduct() : \"api\") + path\n}\n\nconst resolveEnvironment = (env: Environment): Environment => {\n if (env === \"staging\" && inferEnvironment() === \"testing\") return \"testing\"\n return env\n}\n\nexport const inferEnvironment = () => {\n const origin = window.location.origin\n\n if (origin.endsWith(\"-testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\".testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"-staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\".staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\".planningcenteronline.com\")) return \"production\"\n if (origin.endsWith(\".churchcenter.com\")) return \"production\"\n if (origin.endsWith(\"/churchcenter.com\")) return \"production\"\n if (origin.endsWith(\".planningcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\".churchcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\"pco.codes\")) return \"development\"\n if (origin.endsWith(\"pco.dev\")) return \"development\"\n if (origin.endsWith(\"pco.test\")) return \"development\"\n if (origin.endsWith(\"churchcenter.test\")) return \"development\"\n\n return \"production\"\n}\n/**\n * If the hostname is a Protonova URL, get the env from the subdomain. Defaults to main.\n * Example: my-cool-change.accounts.planningcenter.ninja -> my-cool-change\n * @returns {string}\n */\nconst prototypeEnv = () => {\n const result = location?.hostname?.match(\n /(?:www\\.)?(.+)\\..+\\.planningcenter\\.ninja/,\n )\n\n if (result && result[1] !== \"localhost\") {\n return result[1]\n }\n\n return \"main\"\n}\n\nconst worktreeName = (productName: string) => {\n const match = location?.hostname?.match(/^(.+?)\\.(.+?)\\.pco\\.\\w+$/)\n if (match && match[2] === productName) return match[1]\n return null\n}\n\nconst domain = () => {\n const result = location.hostname.match(/planningcenter(online)?.com/)\n\n if (result === null) {\n return \"planningcenteronline.com\"\n } else {\n return result[0]\n }\n}\n\nconst extractSubdomainsFrom = (host, tldLength = 1) => {\n return host.split(\".\").slice(0, (1 + tldLength) * -1)\n}\n\nconst inferProduct = () => {\n const subdomains = extractSubdomainsFrom(window.location.hostname)\n\n return subdomains[\n inferEnvironment() === \"prototype\" ? subdomains.length - 1 : 0\n ].replace(/-staging$/, \"\").replace(/-testing$/, \"\")\n}\n"],"names":["legacy","env","productName","getCurrentProtocol","location","protocol","domain","tld","hostname","match","error","console","prefix","worktreeName","prototypeEnv","pcoUrl","product","inferEnvironment","resolveEnvironment","pcoApiUrl","squiggly","path","inferProduct","origin","window","endsWith","_location","_location$hostname","result","_location2","_location2$hostname","subdomains","host","tldLength","split","slice","extractSubdomainsFrom","length","replace"],"mappings":"AAsBMA,MAAAA,EAAUC,GAAsBC,IACpC,IAAMD,IAAOC,EAAc,OAE3B,MAAMC,EAAqB,IACD,oBAAbC,UAA4BA,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AOE,SAAS,6BAH6C,UAI7DF,EAAOE,SAAS,8BAChBF,EAAOE,SAAS,sBAChBF,EAAOE,SAAS,qBAFqC,aAGrDF,EAAOE,SAAS,0BAChBF,EAAOE,SAAS,uBADiC,YAEjDF,EAAOE,SAAS,cAChBF,EAAOE,SAAS,YAChBF,EAAOE,SAAS,aAChBF,EAAOE,SAAS,qBAHqB,cAKlC,cAOHX,EAAe,KACnB,IAAAY,EAAAC,EAAA,MAAMC,EAAS,OAAHF,EAAGtB,WAAA,OAAAuB,EAAAD,EAAUlB,eAAV,EAAAmB,EAAoBlB,MACjC,6CAGF,OAAImB,GAAwB,cAAdA,EAAO,GACZA,EAAO,GAGT,QAGHf,EAAgBX,IACpB,IAAA2B,EAAAC,EAAA,MAAMrB,EAAQ,OAAHoB,EAAGzB,WAAA,OAAA0B,EAAAD,EAAUrB,eAAV,EAAAsB,EAAoBrB,MAAM,4BACxC,OAAIA,GAASA,EAAM,KAAOP,EAAoBO,EAAM,SAIhDH,EAAS,KACb,MAAMsB,EAASxB,SAASI,SAASC,MAAM,+BAEvC,OAAe,OAAXmB,EACK,2BAEAA,EAAO,EACf,EAOGN,EAAe,KACnB,MAAMS,EALsB,EAACC,EAAMC,EAAY,IAKNT,OAAOpB,SAASI,SAJ7C0B,MAAM,KAAKC,MAAM,GAAsB,GAAlB,EAAIF,IAIlBG,GAEnB,OAAOL,EACkB,cAAvBd,IAAqCc,EAAWM,OAAS,EAAI,GAC7DC,QAAQ,YAAa,IAAIA,QAAQ,YAAa,GAFzC"}
1
+ {"version":3,"file":"url.modern.js","sources":["../index.ts"],"sourcesContent":["export type Environment =\n | \"production\"\n | \"staging\"\n | \"testing\"\n | \"development\"\n | \"test\"\n | \"prototype\"\n\nexport type Product =\n | \"api\"\n | \"accounts\"\n | \"calendar\"\n | \"check-ins\"\n | \"giving\"\n | \"groups\"\n | \"home\"\n | \"login\"\n | \"people\"\n | \"publishing\"\n | \"registrations\"\n | \"services\"\n\nconst legacy = (env: Environment) => (productName: Product) => {\n env = resolveEnvironment(env)\n if (!(env && productName)) return\n\n const getCurrentProtocol = () => {\n if (typeof location !== 'undefined' && location && location.protocol) {\n return location.protocol === 'https:' ? 'https' : 'http'\n }\n return 'http'\n }\n\n switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${domain()}`\n case \"testing\":\n return `https://${productName}-testing.${domain()}`\n case \"development\": {\n let tld = \"test\"\n\n try {\n tld = location.hostname.match(/\\pco\\.(\\w+)$/)[1]\n } catch (error) {\n // don't show warning in Topbar's local dev env\n if (location.hostname !== \"localhost\") {\n console.error(`${location.hostname} is not a supported dev TLD`)\n }\n }\n\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.${tld}`\n }\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\": {\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.test`\n }\n default:\n return `http://${productName}.${domain()}`\n }\n}\n\nexport default legacy\n\nexport function pcoUrl(\n product: Product,\n { env = inferEnvironment() }: { env?: Environment } = {},\n) {\n return legacy(env)(product)\n}\n\nexport function pcoApiUrl(\n product: Product,\n {\n env = inferEnvironment(),\n squiggly = true,\n }: { env?: Environment; squiggly?: boolean } = {},\n) {\n let path = squiggly ? \"/~api\" : \"\"\n path += `/${product}/v2`\n\n return legacy(env)(squiggly ? inferProduct() : \"api\") + path\n}\n\nconst resolveEnvironment = (env: Environment): Environment => {\n if (env === \"staging\" && inferEnvironment() === \"testing\") return \"testing\"\n return env\n}\n\nexport const inferEnvironment = () => {\n const origin = window.location.origin\n\n if (origin.endsWith(\"-testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\".testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"-staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\".staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\".planningcenteronline.com\")) return \"production\"\n if (origin.endsWith(\".churchcenter.com\")) return \"production\"\n if (origin.endsWith(\"/churchcenter.com\")) return \"production\"\n if (origin.endsWith(\".planningcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\".churchcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\"pco.codes\")) return \"development\"\n if (origin.endsWith(\"pco.dev\")) return \"development\"\n if (origin.endsWith(\"pco.test\")) return \"development\"\n if (origin.endsWith(\"churchcenter.test\")) return \"development\"\n\n return \"production\"\n}\n/**\n * If the hostname is a Protonova URL, get the env from the subdomain. Defaults to main.\n * Example: my-cool-change.accounts.planningcenter.ninja -> my-cool-change\n * @returns {string}\n */\nconst prototypeEnv = () => {\n const result = location?.hostname?.match(\n /(?:www\\.)?(.+)\\..+\\.planningcenter\\.ninja/,\n )\n\n if (result && result[1] !== \"localhost\") {\n return result[1]\n }\n\n return \"main\"\n}\n\nconst worktreeName = (productName: string) => {\n const match = location?.hostname?.match(/^(.+?)\\.(.+?)\\.pco\\.\\w+$/)\n if (match && match[2] === productName) return match[1]\n return null\n}\n\nconst domain = () => {\n const result = location.hostname.match(/planningcenter(online)?.com/)\n\n if (result === null) {\n return \"planningcenteronline.com\"\n } else {\n return result[0]\n }\n}\n\nconst extractSubdomainsFrom = (host, tldLength = 1) => {\n return host.split(\".\").slice(0, (1 + tldLength) * -1)\n}\n\nconst inferProduct = () => {\n const subdomains = extractSubdomainsFrom(window.location.hostname)\n\n return subdomains[\n inferEnvironment() === \"prototype\" ? subdomains.length - 1 : 0\n ].replace(/-staging$/, \"\").replace(/-testing$/, \"\")\n}\n"],"names":["legacy","env","productName","resolveEnvironment","getCurrentProtocol","location","protocol","domain","tld","hostname","match","error","console","prefix","worktreeName","prototypeEnv","pcoUrl","product","inferEnvironment","pcoApiUrl","squiggly","path","inferProduct","origin","window","endsWith","_location","_location$hostname","result","_location2","_location2$hostname","subdomains","host","tldLength","split","slice","extractSubdomainsFrom","length","replace"],"mappings":"AAsBMA,MAAAA,EAAUC,GAAsBC,IAEpC,KADAD,EAAME,EAAmBF,MACZC,EAAc,OAE3B,MAAME,EAAqB,IACD,oBAAbC,UAA4BA,UAAYA,SAASC,UAC7B,WAAtBD,SAASC,SAAwB,QAEnC,OAGT,OAAQL,GACN,IAAK,aACH,iBAAkBC,KAAeK,MACnC,IAAK,UACH,iBAAkBL,aAAuBK,MAC3C,IAAK,UACH,iBAAkBL,aAAuBK,MAC3C,IAAK,cAAe,CAClB,IAAIC,EAAM,OAEV,IACEA,EAAMH,SAASI,SAASC,MAAM,gBAAgB,EAM/C,CALC,MAAOC,GAEmB,cAAtBN,SAASI,UACXG,QAAQD,MAAM,GAAGN,SAASI,sCAE7B,CAED,MAAMI,EAASC,EAAaZ,GAC5B,MAAO,GAAGE,SAA0BS,EAAY,GAAAA,KAAY,KAAKX,SAAmBM,GACrF,CACD,IAAK,YACH,iBAAkBO,OAAkBb,yBACtC,IAAK,OAAQ,CACX,MAAMW,EAASC,EAAaZ,GAC5B,SAAUE,SAA0BS,EAAS,GAAGA,KAAY,KAAKX,YAClE,CACD,QACE,gBAAiBA,KAAeK,MA7BpC,EAmCcS,SAAAA,EACdC,GACAhB,IAAEA,EAAMiB,KAA8C,CAAA,GAEtD,OAAOlB,EAAOC,EAAPD,CAAYiB,EACpB,CAEeE,SAAAA,EACdF,GACAhB,IACEA,EAAMiB,IADRE,SAEEA,GAAW,GACkC,CALjC,GAOd,IAAIC,EAAOD,EAAW,QAAU,GAGhC,OAFAC,GAAQ,IAAIJ,OAELjB,EAAOC,EAAPD,CAAYoB,EAAWE,IAAiB,OAASD,CACzD,CAED,MAAMlB,EAAsBF,GACd,YAARA,GA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&location&&location.protocol&&"https:"===location.protocol?"https":"http"};switch(n){case"production":return"https://"+t+"."+a();case"staging":return"https://"+t+"-staging."+a();case"testing":return"https://"+t+"-testing."+a();case"development":var o="test";try{o=location.hostname.match(/\pco\.(\w+)$/)[1]}catch(n){"localhost"!==location.hostname&&console.error(location.hostname+" is not a supported dev TLD")}var i=r(t);return e()+"://"+(i?i+".":"")+t+".pco."+o;case"prototype":return"https://"+c()+"."+t+".planningcenter.ninja";case"test":var s=r(t);return e()+"://"+(s?s+".":"")+t+".pco.test";default:return"http://"+t+"."+a()}}}};function t(t,e){var c=(void 0===e?{}:e).env,r=void 0===c?i():c;return r=o(r),n(r)(t)}function e(t,e){var c=void 0===e?{}:e,r=c.env,a=void 0===r?i():r,l=c.squiggly,h=void 0===l||l;a=o(a);var u=h?"/~api":"";return u+="/"+t+"/v2",n(a)(h?s():"api")+u}var o=function(n){return"staging"===n&&"testing"===i()?"testing":n},i=function(){var n=window.location.origin;return n.endsWith("-testing.planningcenteronline.com")||n.endsWith("/testing.planningcenteronline.com")||n.endsWith(".testing.churchcenter.com")||n.endsWith("/testing.churchcenter.com")?"testing":n.endsWith("-staging.planningcenteronline.com")||n.endsWith("/staging.planningcenteronline.com")||n.endsWith(".staging.churchcenter.com")||n.endsWith("/staging.churchcenter.com")?"staging":n.endsWith(".planningcenteronline.com")||n.endsWith(".churchcenter.com")||n.endsWith("/churchcenter.com")?"production":n.endsWith(".planningcenter.ninja")||n.endsWith(".churchcenter.ninja")?"prototype":n.endsWith("pco.codes")||n.endsWith("pco.dev")||n.endsWith("pco.test")||n.endsWith("churchcenter.test")?"development":"production"},c=function(){var n,t,e=null==(n=location)||null==(t=n.hostname)?void 0:t.match(/(?:www\.)?(.+)\..+\.planningcenter\.ninja/);return e&&"localhost"!==e[1]?e[1]:"main"},r=function(n){var t,e,o=null==(t=location)||null==(e=t.hostname)?void 0:e.match(/^(.+?)\.(.+?)\.pco\.\w+$/);return o&&o[2]===n?o[1]:null},a=function(){var n=location.hostname.match(/planningcenter(online)?.com/);return null===n?"planningcenteronline.com":n[0]},s=function(){var n,t=(void 0===n&&(n=1),window.location.hostname.split(".").slice(0,-1*(1+n)));return t["prototype"===i()?t.length-1:0].replace(/-staging$/,"").replace(/-testing$/,"")};export{n as default,i as inferEnvironment,e as pcoApiUrl,t as pcoUrl};
1
+ var n=function(n){return function(t){if((n=o(n))&&t){var e=function(){return"undefined"!=typeof location&&location&&location.protocol&&"https:"===location.protocol?"https":"http"};switch(n){case"production":return"https://"+t+"."+a();case"staging":return"https://"+t+"-staging."+a();case"testing":return"https://"+t+"-testing."+a();case"development":var i="test";try{i=location.hostname.match(/\pco\.(\w+)$/)[1]}catch(n){"localhost"!==location.hostname&&console.error(location.hostname+" is not a supported dev TLD")}var s=r(t);return e()+"://"+(s?s+".":"")+t+".pco."+i;case"prototype":return"https://"+c()+"."+t+".planningcenter.ninja";case"test":var l=r(t);return e()+"://"+(l?l+".":"")+t+".pco.test";default:return"http://"+t+"."+a()}}}};function t(t,e){var o=(void 0===e?{}:e).env,c=void 0===o?i():o;return n(c)(t)}function e(t,e){var o=void 0===e?{}:e,c=o.env,r=void 0===c?i():c,a=o.squiggly,l=void 0===a||a,h=l?"/~api":"";return h+="/"+t+"/v2",n(r)(l?s():"api")+h}var o=function(n){return"staging"===n&&"testing"===i()?"testing":n},i=function(){var n=window.location.origin;return n.endsWith("-testing.planningcenteronline.com")||n.endsWith("/testing.planningcenteronline.com")||n.endsWith(".testing.churchcenter.com")||n.endsWith("/testing.churchcenter.com")?"testing":n.endsWith("-staging.planningcenteronline.com")||n.endsWith("/staging.planningcenteronline.com")||n.endsWith(".staging.churchcenter.com")||n.endsWith("/staging.churchcenter.com")?"staging":n.endsWith(".planningcenteronline.com")||n.endsWith(".churchcenter.com")||n.endsWith("/churchcenter.com")?"production":n.endsWith(".planningcenter.ninja")||n.endsWith(".churchcenter.ninja")?"prototype":n.endsWith("pco.codes")||n.endsWith("pco.dev")||n.endsWith("pco.test")||n.endsWith("churchcenter.test")?"development":"production"},c=function(){var n,t,e=null==(n=location)||null==(t=n.hostname)?void 0:t.match(/(?:www\.)?(.+)\..+\.planningcenter\.ninja/);return e&&"localhost"!==e[1]?e[1]:"main"},r=function(n){var t,e,o=null==(t=location)||null==(e=t.hostname)?void 0:e.match(/^(.+?)\.(.+?)\.pco\.\w+$/);return o&&o[2]===n?o[1]:null},a=function(){var n=location.hostname.match(/planningcenter(online)?.com/);return null===n?"planningcenteronline.com":n[0]},s=function(){var n,t=(void 0===n&&(n=1),window.location.hostname.split(".").slice(0,-1*(1+n)));return t["prototype"===i()?t.length-1:0].replace(/-staging$/,"").replace(/-testing$/,"")};export{n as default,i as inferEnvironment,e as pcoApiUrl,t as pcoUrl};
2
2
  //# sourceMappingURL=url.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"url.module.js","sources":["../index.ts"],"sourcesContent":["export type Environment =\n | \"production\"\n | \"staging\"\n | \"testing\"\n | \"development\"\n | \"test\"\n | \"prototype\"\n\nexport type Product =\n | \"api\"\n | \"accounts\"\n | \"calendar\"\n | \"check-ins\"\n | \"giving\"\n | \"groups\"\n | \"home\"\n | \"login\"\n | \"people\"\n | \"publishing\"\n | \"registrations\"\n | \"services\"\n\nconst legacy = (env: Environment) => (productName: Product) => {\n if (!(env && productName)) return\n\n const getCurrentProtocol = () => {\n if (typeof location !== 'undefined' && location && location.protocol) {\n return location.protocol === 'https:' ? 'https' : 'http'\n }\n return 'http'\n }\n\n switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${domain()}`\n case \"testing\":\n return `https://${productName}-testing.${domain()}`\n case \"development\": {\n let tld = \"test\"\n\n try {\n tld = location.hostname.match(/\\pco\\.(\\w+)$/)[1]\n } catch (error) {\n // don't show warning in Topbar's local dev env\n if (location.hostname !== \"localhost\") {\n console.error(`${location.hostname} is not a supported dev TLD`)\n }\n }\n\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.${tld}`\n }\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\": {\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.test`\n }\n default:\n return `http://${productName}.${domain()}`\n }\n}\n\nexport default legacy\n\nexport function pcoUrl(\n product: Product,\n { env = inferEnvironment() }: { env?: Environment } = {},\n) {\n env = resolveEnvironment(env)\n return legacy(env)(product)\n}\n\nexport function pcoApiUrl(\n product: Product,\n {\n env = inferEnvironment(),\n squiggly = true,\n }: { env?: Environment; squiggly?: boolean } = {},\n) {\n env = resolveEnvironment(env)\n let path = squiggly ? \"/~api\" : \"\"\n path += `/${product}/v2`\n\n return legacy(env)(squiggly ? inferProduct() : \"api\") + path\n}\n\nconst resolveEnvironment = (env: Environment): Environment => {\n if (env === \"staging\" && inferEnvironment() === \"testing\") return \"testing\"\n return env\n}\n\nexport const inferEnvironment = () => {\n const origin = window.location.origin\n\n if (origin.endsWith(\"-testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\".testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"-staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\".staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\".planningcenteronline.com\")) return \"production\"\n if (origin.endsWith(\".churchcenter.com\")) return \"production\"\n if (origin.endsWith(\"/churchcenter.com\")) return \"production\"\n if (origin.endsWith(\".planningcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\".churchcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\"pco.codes\")) return \"development\"\n if (origin.endsWith(\"pco.dev\")) return \"development\"\n if (origin.endsWith(\"pco.test\")) return \"development\"\n if (origin.endsWith(\"churchcenter.test\")) return \"development\"\n\n return \"production\"\n}\n/**\n * If the hostname is a Protonova URL, get the env from the subdomain. Defaults to main.\n * Example: my-cool-change.accounts.planningcenter.ninja -> my-cool-change\n * @returns {string}\n */\nconst prototypeEnv = () => {\n const result = location?.hostname?.match(\n /(?:www\\.)?(.+)\\..+\\.planningcenter\\.ninja/,\n )\n\n if (result && result[1] !== \"localhost\") {\n return result[1]\n }\n\n return \"main\"\n}\n\nconst worktreeName = (productName: string) => {\n const match = location?.hostname?.match(/^(.+?)\\.(.+?)\\.pco\\.\\w+$/)\n if (match && match[2] === productName) return match[1]\n return null\n}\n\nconst domain = () => {\n const result = location.hostname.match(/planningcenter(online)?.com/)\n\n if (result === null) {\n return \"planningcenteronline.com\"\n } else {\n return result[0]\n }\n}\n\nconst extractSubdomainsFrom = (host, tldLength = 1) => {\n return host.split(\".\").slice(0, (1 + tldLength) * -1)\n}\n\nconst inferProduct = () => {\n const subdomains = extractSubdomainsFrom(window.location.hostname)\n\n return subdomains[\n inferEnvironment() === \"prototype\" ? subdomains.length - 1 : 0\n ].replace(/-staging$/, \"\").replace(/-testing$/, \"\")\n}\n"],"names":["legacy","env","productName","getCurrentProtocol","location","protocol","domain","tld","hostname","match","error","console","prefix","worktreeName","prototypeEnv","pcoUrl","product","_temp","_ref$env","inferEnvironment","resolveEnvironment","pcoApiUrl","_ref2","_temp2","squiggly","_ref2$squiggly","path","inferProduct","origin","window","endsWith","_location","_location$hostname","result","_location2","_location2$hostname","tldLength","subdomains","split","slice","length","replace"],"mappings":"AAsBMA,IAAAA,EAAS,SAACC,GAAqB,OAAA,SAACC,GACpC,GAAMD,GAAOC,EAAb,CAEA,IAAMC,EAAqB,WACzB,MAAwB,oBAAbC,UAA4BA,UAAYA,SAASC,UAC7B,WAAtBD,SAASC,SAAwB,QAEnC,MACR,EAED,OAAQJ,GACN,IAAK,aACH,MAAA,WAAkBC,EA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EAAOE,SAAS,sCAChBF,EAAOE,SAAS,sCAChBF,EAAOE,SAAS,8BAChBF,EAAOE,SAAS,6BAH6C,UAI7DF,EAAOE,SAAS,8BAChBF,EAAOE,SAAS,sBAChBF,EAAOE,SAAS,qBAFqC,aAGrDF,EAAOE,SAAS,0BAChBF,EAAOE,SAAS,uBADiC,YAEjDF,EAAOE,SAAS,cAChBF,EAAOE,SAAS,YAChBF,EAAOE,SAAS,aAChBF,EAAOE,SAAS,qBAHqB,cAKlC,YACR,EAMKhB,EAAe,WAAK,IAAAiB,EAAAC,EAClBC,EAAM,SAAG7B,WAAH,OAAA4B,EAAGD,EAAUvB,eAAb,EAAGwB,EAAoBvB,MACjC,6CAGF,OAAIwB,GAAwB,cAAdA,EAAO,GACZA,EAAO,GAGT,MACR,EAEKpB,EAAe,SAACX,GACpB,IAAAgC,EAAAC,EAAM1B,EAAQ,OAAHyB,EAAG9B,WAAA,OAAA+B,EAAAD,EAAU1B,eAAV,EAAA2B,EAAoB1B,MAAM,4BACxC,OAAIA,GAASA,EAAM,KAAOP,EAAoBO,EAAM,GAC7C,IACR,EAEKH,EAAS,WACb,IAAM2B,EAAS7B,SAASI,SAASC,MAAM,+BAEvC,OAAe,OAAXwB,EACK,2BAEAA,EAAO,EAEjB,EAMKN,EAAe,WACnB,IALmCS,EAK7BC,YAL6BD,IAAAA,EAAY,GAKNP,OAAOzB,SAASI,SAJ7C8B,MAAM,KAAKC,MAAM,GAAsB,GAAlB,EAAIH,KAMrC,OAAOC,EACkB,cAAvBlB,IAAqCkB,EAAWG,OAAS,EAAI,GAC7DC,QAAQ,YAAa,IAAIA,QAAQ,YAAa,GACjD"}
1
+ {"version":3,"file":"url.module.js","sources":["../index.ts"],"sourcesContent":["export type Environment =\n | \"production\"\n | \"staging\"\n | \"testing\"\n | \"development\"\n | \"test\"\n | \"prototype\"\n\nexport type Product =\n | \"api\"\n | \"accounts\"\n | \"calendar\"\n | \"check-ins\"\n | \"giving\"\n | \"groups\"\n | \"home\"\n | \"login\"\n | \"people\"\n | \"publishing\"\n | \"registrations\"\n | \"services\"\n\nconst legacy = (env: Environment) => (productName: Product) => {\n env = resolveEnvironment(env)\n if (!(env && productName)) return\n\n const getCurrentProtocol = () => {\n if (typeof location !== 'undefined' && location && location.protocol) {\n return location.protocol === 'https:' ? 'https' : 'http'\n }\n return 'http'\n }\n\n switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${domain()}`\n case \"testing\":\n return `https://${productName}-testing.${domain()}`\n case \"development\": {\n let tld = \"test\"\n\n try {\n tld = location.hostname.match(/\\pco\\.(\\w+)$/)[1]\n } catch (error) {\n // don't show warning in Topbar's local dev env\n if (location.hostname !== \"localhost\") {\n console.error(`${location.hostname} is not a supported dev TLD`)\n }\n }\n\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.${tld}`\n }\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\": {\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.test`\n }\n default:\n return `http://${productName}.${domain()}`\n }\n}\n\nexport default legacy\n\nexport function pcoUrl(\n product: Product,\n { env = inferEnvironment() }: { env?: Environment } = {},\n) {\n return legacy(env)(product)\n}\n\nexport function pcoApiUrl(\n product: Product,\n {\n env = inferEnvironment(),\n squiggly = true,\n }: { env?: Environment; squiggly?: boolean } = {},\n) {\n let path = squiggly ? \"/~api\" : \"\"\n path += `/${product}/v2`\n\n return legacy(env)(squiggly ? inferProduct() : \"api\") + path\n}\n\nconst resolveEnvironment = (env: Environment): Environment => {\n if (env === \"staging\" && inferEnvironment() === \"testing\") return \"testing\"\n return env\n}\n\nexport const inferEnvironment = () => {\n const origin = window.location.origin\n\n if (origin.endsWith(\"-testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\".testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"-staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\".staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\".planningcenteronline.com\")) return \"production\"\n if (origin.endsWith(\".churchcenter.com\")) return \"production\"\n if (origin.endsWith(\"/churchcenter.com\")) return \"production\"\n if (origin.endsWith(\".planningcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\".churchcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\"pco.codes\")) return \"development\"\n if (origin.endsWith(\"pco.dev\")) return \"development\"\n if (origin.endsWith(\"pco.test\")) return \"development\"\n if (origin.endsWith(\"churchcenter.test\")) return \"development\"\n\n return \"production\"\n}\n/**\n * If the hostname is a Protonova URL, get the env from the subdomain. Defaults to main.\n * Example: my-cool-change.accounts.planningcenter.ninja -> my-cool-change\n * @returns {string}\n */\nconst prototypeEnv = () => {\n const result = location?.hostname?.match(\n /(?:www\\.)?(.+)\\..+\\.planningcenter\\.ninja/,\n )\n\n if (result && result[1] !== \"localhost\") {\n return result[1]\n }\n\n return \"main\"\n}\n\nconst worktreeName = (productName: string) => {\n const match = location?.hostname?.match(/^(.+?)\\.(.+?)\\.pco\\.\\w+$/)\n if (match && match[2] === productName) return match[1]\n return null\n}\n\nconst domain = () => {\n const result = location.hostname.match(/planningcenter(online)?.com/)\n\n if (result === null) {\n return \"planningcenteronline.com\"\n } else {\n return result[0]\n }\n}\n\nconst extractSubdomainsFrom = (host, tldLength = 1) => {\n return host.split(\".\").slice(0, (1 + tldLength) * -1)\n}\n\nconst inferProduct = () => {\n const subdomains = extractSubdomainsFrom(window.location.hostname)\n\n return subdomains[\n inferEnvironment() === \"prototype\" ? subdomains.length - 1 : 0\n ].replace(/-staging$/, \"\").replace(/-testing$/, \"\")\n}\n"],"names":["legacy","env","productName","resolveEnvironment","getCurrentProtocol","location","protocol","domain","tld","hostname","match","error","console","prefix","worktreeName","prototypeEnv","pcoUrl","product","_temp","_ref$env","inferEnvironment","pcoApiUrl","_temp2","_ref2$env","_ref2","squiggly","_ref2$squiggly","path","inferProduct","origin","window","endsWith","result","_location","_location$hostname","_location2","_location2$hostname","tldLength","subdomains","split","slice","length","replace"],"mappings":"AAsBMA,IAAAA,EAAS,SAACC,GAAqB,OAAA,SAACC,GAEpC,IADAD,EAAME,EAAmBF,KACZC,EAAb,CAEA,IAAME,EAAqB,WACzB,MAAwB,oBAAbC,UAA4BA,UAAYA,SAASC,UAC7B,WAAtBD,SAASC,SAAwB,QAEnC,MACR,EAED,OAAQL,GACN,IAAK,aACH,iBAAkBC,EAAlB,IAAiCK,IACnC,IAAK,UACH,iBAAkBL,EAAlB,YAAyCK,IAC3C,IAAK,UACH,iBAAkBL,EAAlB,YAAyCK,IAC3C,IAAK,cACH,IAAIC,EAAM,OAEV,IACEA,EAAMH,SAASI,SAASC,MAAM,gBAAgB,EAM/C,CALC,MAAOC,GAEmB,cAAtBN,SAASI,UACXG,QAAQD,MAASN,SAASI,SAA1B,8BAEH,CAED,IAAMI,EAASC,EAAaZ,GAC5B,OAAUE,WAA0BS,EAAYA,EAAY,IAAA,IAAKX,EAAjE,QAAoFM,EAEtF,IAAK,YACH,MAAA,WAAkBO,IAAlB,IAAoCb,EACtC,wBAAA,IAAK,OACH,IAAMW,EAASC,EAAaZ,GAC5B,OAAUE,IAA0BS,OAAAA,EAAYA,EAAN,IAAkB,IAAKX,cAEnE,QACE,gBAAiBA,EAAjB,IAAgCK,IAtCT,CAwC5B,CA1Cc,WA8CCS,EACdC,EADIC,OAEoDC,cAAF,CAAA,EAAED,GAAtDjB,IAAAA,aAAMmB,MAER,OAAOpB,EAAOC,EAAPD,CAAYiB,EACpB,UAEeI,EACdJ,EADcK,oBAKiC,CAA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M,KAAKC,MAAM,GAAsB,GAAlB,EAAIH,KAMrC,OAAOC,EACkB,cAAvBlB,IAAqCkB,EAAWG,OAAS,EAAI,GAC7DC,QAAQ,YAAa,IAAIA,QAAQ,YAAa,GACjD"}
package/dist/url.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((n||self).PLANNINGCENTER=n.PLANNINGCENTER||{},n.PLANNINGCENTER.url={}))}(this,function(n){var t=function(n){return function(t){if(n&&t){var e=function(){return"undefined"!=typeof location&&location&&location.protocol&&"https:"===location.protocol?"https":"http"};switch(n){case"production":return"https://"+t+"."+r();case"staging":return"https://"+t+"-staging."+r();case"testing":return"https://"+t+"-testing."+r();case"development":var o="test";try{o=location.hostname.match(/\pco\.(\w+)$/)[1]}catch(n){"localhost"!==location.hostname&&console.error(location.hostname+" is not a supported dev TLD")}var a=c(t);return e()+"://"+(a?a+".":"")+t+".pco."+o;case"prototype":return"https://"+i()+"."+t+".planningcenter.ninja";case"test":var s=c(t);return e()+"://"+(s?s+".":"")+t+".pco.test";default:return"http://"+t+"."+r()}}}},e=function(n){return"staging"===n&&"testing"===o()?"testing":n},o=function(){var n=window.location.origin;return n.endsWith("-testing.planningcenteronline.com")||n.endsWith("/testing.planningcenteronline.com")||n.endsWith(".testing.churchcenter.com")||n.endsWith("/testing.churchcenter.com")?"testing":n.endsWith("-staging.planningcenteronline.com")||n.endsWith("/staging.planningcenteronline.com")||n.endsWith(".staging.churchcenter.com")||n.endsWith("/staging.churchcenter.com")?"staging":n.endsWith(".planningcenteronline.com")||n.endsWith(".churchcenter.com")||n.endsWith("/churchcenter.com")?"production":n.endsWith(".planningcenter.ninja")||n.endsWith(".churchcenter.ninja")?"prototype":n.endsWith("pco.codes")||n.endsWith("pco.dev")||n.endsWith("pco.test")||n.endsWith("churchcenter.test")?"development":"production"},i=function(){var n,t,e=null==(n=location)||null==(t=n.hostname)?void 0:t.match(/(?:www\.)?(.+)\..+\.planningcenter\.ninja/);return e&&"localhost"!==e[1]?e[1]:"main"},c=function(n){var t,e,o=null==(t=location)||null==(e=t.hostname)?void 0:e.match(/^(.+?)\.(.+?)\.pco\.\w+$/);return o&&o[2]===n?o[1]:null},r=function(){var n=location.hostname.match(/planningcenter(online)?.com/);return null===n?"planningcenteronline.com":n[0]};n.default=t,n.inferEnvironment=o,n.pcoApiUrl=function(n,i){var c=void 0===i?{}:i,r=c.env,a=void 0===r?o():r,s=c.squiggly,l=void 0===s||s;a=e(a);var h,p,u=l?"/~api":"";return u+="/"+n+"/v2",t(a)(l?(void 0===h&&(h=1),(p=window.location.hostname.split(".").slice(0,-1*(1+h)))["prototype"===o()?p.length-1:0].replace(/-staging$/,"").replace(/-testing$/,"")):"api")+u},n.pcoUrl=function(n,i){var c=(void 0===i?{}:i).env,r=void 0===c?o():c;return r=e(r),t(r)(n)}});
1
+ !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((n||self).PLANNINGCENTER=n.PLANNINGCENTER||{},n.PLANNINGCENTER.url={}))}(this,function(n){var t=function(n){return function(t){if((n=e(n))&&t){var o=function(){return"undefined"!=typeof location&&location&&location.protocol&&"https:"===location.protocol?"https":"http"};switch(n){case"production":return"https://"+t+"."+r();case"staging":return"https://"+t+"-staging."+r();case"testing":return"https://"+t+"-testing."+r();case"development":var a="test";try{a=location.hostname.match(/\pco\.(\w+)$/)[1]}catch(n){"localhost"!==location.hostname&&console.error(location.hostname+" is not a supported dev TLD")}var s=c(t);return o()+"://"+(s?s+".":"")+t+".pco."+a;case"prototype":return"https://"+i()+"."+t+".planningcenter.ninja";case"test":var l=c(t);return o()+"://"+(l?l+".":"")+t+".pco.test";default:return"http://"+t+"."+r()}}}},e=function(n){return"staging"===n&&"testing"===o()?"testing":n},o=function(){var n=window.location.origin;return n.endsWith("-testing.planningcenteronline.com")||n.endsWith("/testing.planningcenteronline.com")||n.endsWith(".testing.churchcenter.com")||n.endsWith("/testing.churchcenter.com")?"testing":n.endsWith("-staging.planningcenteronline.com")||n.endsWith("/staging.planningcenteronline.com")||n.endsWith(".staging.churchcenter.com")||n.endsWith("/staging.churchcenter.com")?"staging":n.endsWith(".planningcenteronline.com")||n.endsWith(".churchcenter.com")||n.endsWith("/churchcenter.com")?"production":n.endsWith(".planningcenter.ninja")||n.endsWith(".churchcenter.ninja")?"prototype":n.endsWith("pco.codes")||n.endsWith("pco.dev")||n.endsWith("pco.test")||n.endsWith("churchcenter.test")?"development":"production"},i=function(){var n,t,e=null==(n=location)||null==(t=n.hostname)?void 0:t.match(/(?:www\.)?(.+)\..+\.planningcenter\.ninja/);return e&&"localhost"!==e[1]?e[1]:"main"},c=function(n){var t,e,o=null==(t=location)||null==(e=t.hostname)?void 0:e.match(/^(.+?)\.(.+?)\.pco\.\w+$/);return o&&o[2]===n?o[1]:null},r=function(){var n=location.hostname.match(/planningcenter(online)?.com/);return null===n?"planningcenteronline.com":n[0]};n.default=t,n.inferEnvironment=o,n.pcoApiUrl=function(n,e){var i,c,r=void 0===e?{}:e,a=r.env,s=void 0===a?o():a,l=r.squiggly,h=void 0===l||l,p=h?"/~api":"";return p+="/"+n+"/v2",t(s)(h?(void 0===i&&(i=1),(c=window.location.hostname.split(".").slice(0,-1*(1+i)))["prototype"===o()?c.length-1:0].replace(/-staging$/,"").replace(/-testing$/,"")):"api")+p},n.pcoUrl=function(n,e){var i=(void 0===e?{}:e).env,c=void 0===i?o():i;return t(c)(n)}});
2
2
  //# sourceMappingURL=url.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"url.umd.js","sources":["../index.ts"],"sourcesContent":["export type Environment =\n | \"production\"\n | \"staging\"\n | \"testing\"\n | \"development\"\n | \"test\"\n | \"prototype\"\n\nexport type Product =\n | \"api\"\n | \"accounts\"\n | \"calendar\"\n | \"check-ins\"\n | \"giving\"\n | \"groups\"\n | \"home\"\n | \"login\"\n | \"people\"\n | \"publishing\"\n | \"registrations\"\n | \"services\"\n\nconst legacy = (env: Environment) => (productName: Product) => {\n if (!(env && productName)) return\n\n const getCurrentProtocol = () => {\n if (typeof location !== 'undefined' && location && location.protocol) {\n return location.protocol === 'https:' ? 'https' : 'http'\n }\n return 'http'\n }\n\n switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${domain()}`\n case \"testing\":\n return `https://${productName}-testing.${domain()}`\n case \"development\": {\n let tld = \"test\"\n\n try {\n tld = location.hostname.match(/\\pco\\.(\\w+)$/)[1]\n } catch (error) {\n // don't show warning in Topbar's local dev env\n if (location.hostname !== \"localhost\") {\n console.error(`${location.hostname} is not a supported dev TLD`)\n }\n }\n\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.${tld}`\n }\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\": {\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.test`\n }\n default:\n return `http://${productName}.${domain()}`\n }\n}\n\nexport default legacy\n\nexport function pcoUrl(\n product: Product,\n { env = inferEnvironment() }: { env?: Environment } = {},\n) {\n env = resolveEnvironment(env)\n return legacy(env)(product)\n}\n\nexport function pcoApiUrl(\n product: Product,\n {\n env = inferEnvironment(),\n squiggly = true,\n }: { env?: Environment; squiggly?: boolean } = {},\n) {\n env = resolveEnvironment(env)\n let path = squiggly ? \"/~api\" : \"\"\n path += `/${product}/v2`\n\n return legacy(env)(squiggly ? inferProduct() : \"api\") + path\n}\n\nconst resolveEnvironment = (env: Environment): Environment => {\n if (env === \"staging\" && inferEnvironment() === \"testing\") return \"testing\"\n return env\n}\n\nexport const inferEnvironment = () => {\n const origin = window.location.origin\n\n if (origin.endsWith(\"-testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\".testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"-staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\".staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\".planningcenteronline.com\")) return \"production\"\n if (origin.endsWith(\".churchcenter.com\")) return \"production\"\n if (origin.endsWith(\"/churchcenter.com\")) return \"production\"\n if (origin.endsWith(\".planningcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\".churchcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\"pco.codes\")) return \"development\"\n if (origin.endsWith(\"pco.dev\")) return \"development\"\n if (origin.endsWith(\"pco.test\")) return \"development\"\n if (origin.endsWith(\"churchcenter.test\")) return \"development\"\n\n return \"production\"\n}\n/**\n * If the hostname is a Protonova URL, get the env from the subdomain. Defaults to main.\n * Example: my-cool-change.accounts.planningcenter.ninja -> my-cool-change\n * @returns {string}\n */\nconst prototypeEnv = () => {\n const result = location?.hostname?.match(\n /(?:www\\.)?(.+)\\..+\\.planningcenter\\.ninja/,\n )\n\n if (result && result[1] !== \"localhost\") {\n return result[1]\n }\n\n return \"main\"\n}\n\nconst worktreeName = (productName: string) => {\n const match = location?.hostname?.match(/^(.+?)\\.(.+?)\\.pco\\.\\w+$/)\n if (match && match[2] === productName) return match[1]\n return null\n}\n\nconst domain = () => {\n const result = location.hostname.match(/planningcenter(online)?.com/)\n\n if (result === null) {\n return \"planningcenteronline.com\"\n } else {\n return result[0]\n }\n}\n\nconst extractSubdomainsFrom = (host, tldLength = 1) => {\n return host.split(\".\").slice(0, (1 + tldLength) * -1)\n}\n\nconst inferProduct = () => {\n const subdomains = extractSubdomainsFrom(window.location.hostname)\n\n return subdomains[\n inferEnvironment() === \"prototype\" ? subdomains.length - 1 : 0\n ].replace(/-staging$/, \"\").replace(/-testing$/, \"\")\n}\n"],"names":["legacy","env","productName","getCurrentProtocol","location","protocol","domain","tld","hostname","match","error","console","prefix","worktreeName","prototypeEnv","resolveEnvironment","inferEnvironment","origin","window","endsWith","_location","_location$hostname","result","_location2","_location2$hostname","pcoApiUrl","product","_ref2","_temp2","squiggly","_ref2$squiggly","tldLength","subdomains","path","split","slice","length","replace","_temp","_ref$env"],"mappings":"oRAsBMA,IAAAA,EAAS,SAACC,GAAqB,OAAA,SAACC,GACpC,GAAMD,GAAOC,EAAb,CAEA,IAAMC,EAAqB,WACzB,MAAwB,oBAAbC,UAA4BA,UAAYA,SAASC,UAC7B,WAAtBD,SAASC,SAAwB,QAEnC,MACR,EAED,OAAQJ,GACN,IAAK,aACH,MAAA,WAAkBC,EAAeI,IAAAA,IACnC,IAAK,UACH,MAAA,WAAkBJ,EAAuBI,YAAAA,IAC3C,IAAK,UACH,MAAA,WAAkBJ,EAAuBI,YAAAA,IAC3C,IAAK,cACH,IAAIC,EAAM,OAEV,IACEA,EAAMH,SAASI,SAASC,MAAM,gBAAgB,EAM/C,CALC,MAAOC,GAEmB,cAAtBN,SAASI,UACXG,QAAQD,MAASN,SAASI,uCAE7B,CAED,IAAMI,EAASC,EAAaX,GAC5B,OAAUC,IAA0BS,OAAAA,EAAYA,EAAN,IAAkB,IAAKV,UAAmBK,EAEtF,IAAK,YACH,iBAAkBO,QAAkBZ,EAApC,wBACF,IAAK,OACH,IAAMU,EAASC,EAAaX,GAC5B,OAAUC,IAAV,OAAoCS,EAAYA,EAAN,IAAkB,IAAKV,cAEnE,QACE,gBAAiBA,EAAjB,IAAgCI,IAtCT,CAwC5B,CAzCc,EAmETS,EAAqB,SAACd,GAC1B,MAAY,YAARA,GAA4C,YAAvBe,IAAyC,UAC3Df,CACR,EAEYe,EAAmB,WAC9B,IAAMC,EAASC,OAAOd,SAASa,OAE/B,OAAIA,EAAOE,SAAS,sCAChBF,EAAOE,SAAS,sCAChBF,EAAOE,SAAS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gB,EAAWI,OAAS,EAAI,GAC7DC,QAAQ,YAAa,IAAIA,QAAQ,YAAa,KAzED,OAASJ,CACzD,oBAnBCP,EADIY,OAEoDC,cAAF,GAAED,GAAtDrC,IAAAA,aAAMe,MAGR,OADAf,EAAMc,EAAmBd,GAClBD,EAAOC,EAAPD,CAAY0B,EACpB"}
1
+ {"version":3,"file":"url.umd.js","sources":["../index.ts"],"sourcesContent":["export type Environment =\n | \"production\"\n | \"staging\"\n | \"testing\"\n | \"development\"\n | \"test\"\n | \"prototype\"\n\nexport type Product =\n | \"api\"\n | \"accounts\"\n | \"calendar\"\n | \"check-ins\"\n | \"giving\"\n | \"groups\"\n | \"home\"\n | \"login\"\n | \"people\"\n | \"publishing\"\n | \"registrations\"\n | \"services\"\n\nconst legacy = (env: Environment) => (productName: Product) => {\n env = resolveEnvironment(env)\n if (!(env && productName)) return\n\n const getCurrentProtocol = () => {\n if (typeof location !== 'undefined' && location && location.protocol) {\n return location.protocol === 'https:' ? 'https' : 'http'\n }\n return 'http'\n }\n\n switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${domain()}`\n case \"testing\":\n return `https://${productName}-testing.${domain()}`\n case \"development\": {\n let tld = \"test\"\n\n try {\n tld = location.hostname.match(/\\pco\\.(\\w+)$/)[1]\n } catch (error) {\n // don't show warning in Topbar's local dev env\n if (location.hostname !== \"localhost\") {\n console.error(`${location.hostname} is not a supported dev TLD`)\n }\n }\n\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.${tld}`\n }\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\": {\n const prefix = worktreeName(productName)\n return `${getCurrentProtocol()}://${prefix ? `${prefix}.` : ''}${productName}.pco.test`\n }\n default:\n return `http://${productName}.${domain()}`\n }\n}\n\nexport default legacy\n\nexport function pcoUrl(\n product: Product,\n { env = inferEnvironment() }: { env?: Environment } = {},\n) {\n return legacy(env)(product)\n}\n\nexport function pcoApiUrl(\n product: Product,\n {\n env = inferEnvironment(),\n squiggly = true,\n }: { env?: Environment; squiggly?: boolean } = {},\n) {\n let path = squiggly ? \"/~api\" : \"\"\n path += `/${product}/v2`\n\n return legacy(env)(squiggly ? inferProduct() : \"api\") + path\n}\n\nconst resolveEnvironment = (env: Environment): Environment => {\n if (env === \"staging\" && inferEnvironment() === \"testing\") return \"testing\"\n return env\n}\n\nexport const inferEnvironment = () => {\n const origin = window.location.origin\n\n if (origin.endsWith(\"-testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.planningcenteronline.com\")) return \"testing\"\n if (origin.endsWith(\".testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"/testing.churchcenter.com\")) return \"testing\"\n if (origin.endsWith(\"-staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.planningcenteronline.com\")) return \"staging\"\n if (origin.endsWith(\".staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\"/staging.churchcenter.com\")) return \"staging\"\n if (origin.endsWith(\".planningcenteronline.com\")) return \"production\"\n if (origin.endsWith(\".churchcenter.com\")) return \"production\"\n if (origin.endsWith(\"/churchcenter.com\")) return \"production\"\n if (origin.endsWith(\".planningcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\".churchcenter.ninja\")) return \"prototype\"\n if (origin.endsWith(\"pco.codes\")) return \"development\"\n if (origin.endsWith(\"pco.dev\")) return \"development\"\n if (origin.endsWith(\"pco.test\")) return \"development\"\n if (origin.endsWith(\"churchcenter.test\")) return \"development\"\n\n return \"production\"\n}\n/**\n * If the hostname is a Protonova URL, get the env from the subdomain. Defaults to main.\n * Example: my-cool-change.accounts.planningcenter.ninja -> my-cool-change\n * @returns {string}\n */\nconst prototypeEnv = () => {\n const result = location?.hostname?.match(\n /(?:www\\.)?(.+)\\..+\\.planningcenter\\.ninja/,\n )\n\n if (result && result[1] !== \"localhost\") {\n return result[1]\n }\n\n return \"main\"\n}\n\nconst worktreeName = (productName: string) => {\n const match = location?.hostname?.match(/^(.+?)\\.(.+?)\\.pco\\.\\w+$/)\n if (match && match[2] === productName) return match[1]\n return null\n}\n\nconst domain = () => {\n const result = location.hostname.match(/planningcenter(online)?.com/)\n\n if (result === null) {\n return \"planningcenteronline.com\"\n } else {\n return result[0]\n }\n}\n\nconst extractSubdomainsFrom = (host, tldLength = 1) => {\n return host.split(\".\").slice(0, (1 + tldLength) * -1)\n}\n\nconst inferProduct = () => {\n const subdomains = extractSubdomainsFrom(window.location.hostname)\n\n return subdomains[\n inferEnvironment() === \"prototype\" ? subdomains.length - 1 : 0\n ].replace(/-staging$/, \"\").replace(/-testing$/, \"\")\n}\n"],"names":["legacy","env","productName","resolveEnvironment","getCurrentProtocol","location","protocol","domain","tld","hostname","match","error","console","prefix","worktreeName","prototypeEnv","inferEnvironment","origin","window","endsWith","result","_location","_location$hostname","_location2","_location2$hostname","product","_temp2","tldLength","subdomains","_ref2$env","_ref2","squiggly","_ref2$squiggly","path","split","slice","length","replace","_temp","_ref$env"],"mappings":"oRAsBMA,IAAAA,EAAS,SAACC,GAAqB,OAAA,SAACC,GAEpC,IADAD,EAAME,EAAmBF,KACZC,EAAb,CAEA,IAAME,EAAqB,WACzB,MAAwB,oBAAbC,UAA4BA,UAAYA,SAASC,UAC7B,WAAtBD,SAASC,SAAwB,QAEnC,MACR,EAED,OAAQL,GACN,IAAK,aACH,iBAAkBC,EAAlB,IAAiCK,IACnC,IAAK,UACH,iBAAkBL,EAAlB,YAAyCK,IAC3C,IAAK,UACH,iBAAkBL,EAAlB,YAAyCK,IAC3C,IAAK,cACH,IAAIC,EAAM,OAEV,IACEA,EAAMH,SAASI,SAASC,MAAM,gBAAgB,EAM/C,CALC,MAAOC,GAEmB,cAAtBN,SAASI,UACXG,QAAQD,MAASN,SAASI,SAA1B,8BAEH,CAED,IAAMI,EAASC,EAAaZ,GAC5B,OAAUE,WAA0BS,EAAYA,EAA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AAC,EAF/C7B,IAAAA,aAAMe,UACNe,SAAAA,OAAW,IAAAC,KAGTC,EAAOF,EAAW,QAAU,GAGhC,OAFAE,OAAYR,EAAR,MAEGzB,EAAOC,EAAPD,CAAY+B,YAgEgBJ,IAAAA,EAAY,IAKzCC,EAAmCV,OAAOb,SAASI,SAJ7CyB,MAAM,KAAKC,MAAM,GAAsB,GAAlB,EAAIR,KAOZ,cAAvBX,IAAqCY,EAAWQ,OAAS,EAAI,GAC7DC,QAAQ,YAAa,IAAIA,QAAQ,YAAa,KAzED,OAASJ,CACzD,oBAjBCR,EADIa,OAEoDC,cAAF,CAAA,EAAED,GAAtDrC,IAAAA,aAAMe,MAER,OAAOhB,EAAOC,EAAPD,CAAYyB,EACpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planningcenter/url",
3
- "version": "3.2.0-qa-60.1",
3
+ "version": "3.2.0-qa-60.2",
4
4
  "description": "url utilities for planning center apps",
5
5
  "source": "index.ts",
6
6
  "main": "./dist/url.js",