@planningcenter/url 2.7.2 → 3.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,42 +2,71 @@
2
2
 
3
3
  A dumb url origin generator in JS.
4
4
 
5
- Builds environment-considered url origins in JS-land, for Planning Center apps.
5
+ Builds environment-considered url origins in JS-land, for Planning Center apps and APIs.
6
6
 
7
- ## Examples
7
+ ## `pcoUrl` Examples
8
8
 
9
9
  ```js
10
- planningcenterurl("development")("api");
10
+ // window.location.origin === "https://people.planningcenteronline.com"
11
+ import { pcoUrl } from "@planningcenter/url"
12
+
13
+ pcoUrl("services")
14
+ // => "https://services.planningcenteronline.com"
15
+
16
+ pcoUrl("api", { env: "development" });
11
17
  // => "http://api.pco.test"
12
18
 
13
- planningcenterurl("staging")("people");
14
- // => "https://accounts.planningcenteronline.com"
19
+ pcoUrl("accounts", { env: "staging" });
20
+ // => "https://accounts-staging.planningcenteronline.com"
15
21
 
16
- planningcenterurl("production")("accounts");
17
- // => "https://people-staging.planningcenteronline.com"
22
+ pcoUrl("api", { env: "development" });
23
+ // => "http://api.pco.test"
24
+
25
+ pcoUrl("people", { env: "staging" });
26
+ // => "https://accounts.planningcenteronline.com"
18
27
  ```
19
28
 
20
- Arguments are curried.
21
- You can make a generic env-considered function.
29
+ ## `pcoApiUrl` Examples
22
30
 
23
31
  ```js
24
- const envURL = planningcenterurl(window.railsEnv);
32
+ // window.location.origin === "https://people.planningcenteronline.com"
33
+ import { pcoApiUrl } from "@planningcenter/url"
25
34
 
26
- envURL("api");
35
+ pcoApiUrl("services")
36
+ // => "https://people.planningcenteronline.com/~api/services/v2"
37
+
38
+ pcoApiUrl("services", { env: "staging" })
39
+ // => "https://people-staging.planningcenteronline.com/~api/services/v2"
40
+
41
+ pcoApiUrl("services", { squiggly: false })
42
+ // => "https://api.planningcenteronline.com/services/v2"
43
+
44
+ pcoApiUrl("services", { squiggly: false, env: "staging" })
45
+ // => "https://api-staging.planningcenteronline.com/services/v2"
27
46
  ```
28
47
 
29
48
  ## In Planning Center Apps
30
49
 
31
- Planning center apps expose the Rails env as the JS global `railsEnv`. Use like so.
50
+ Generally, the environment can be inferred from within Planning Center apps:
32
51
 
33
52
  ```js
34
- planningcenterurl(railsEnv)("api");
53
+ // window.location.origin === "https://people.planningcenteronline.com"
54
+
55
+ pcoUrl("api") // https://api.planningcenteronline.com
56
+ pcoApiUrl("services") // https://people.planningcenteronline.com/~api/services/v2
57
+ ```
58
+
59
+ However, most Planning Center apps also expose the Rails env as the JS global `railsEnv`. Use it like so:
60
+
61
+ ```js
62
+ pcoUrl("api", { env: railsEnv })
63
+ pcoApiUrl("services", { env: railsEnv })
35
64
  ```
36
65
 
37
66
  ## Fetching example
38
67
 
39
68
  ```js
40
- fetch(`${planningcenterurl(env)("api")}/people/v2/me`, {
69
+ fetch(`${pcoApiUrl("people")}/me`, {
41
70
  credentials: "include"
42
71
  })
43
72
  .then(res => res.json())
@@ -58,8 +87,14 @@ fetch(`${planningcenterurl(env)("api")}/people/v2/me`, {
58
87
  Script tag on Rails
59
88
 
60
89
  ```html
61
- <script type="javascript" src="https://unpkg.com/@planningcenter/url"></script>
62
- <!-- exposed as global `planningcenterurl` -->
90
+ <script src="https://unpkg.com/@planningcenter/url"></script>
91
+
92
+ <script>
93
+ const { pcoUrl, pcoApiUrl } = PLANNINGCENTER.url
94
+
95
+ pcoUrl("people"); // https://people.planningcenteronline.com
96
+ pcoApiUrl("people"); // https://{app}.planningcenteronline.com/~api/people/v2
97
+ </script>
63
98
  ```
64
99
 
65
100
  Webpacker on Rails
@@ -69,8 +104,39 @@ yarn add @planningcenter/url
69
104
  ```
70
105
 
71
106
  ```js
72
- /* global railsEnv */
73
- import pcurl from "@planningcenter/url";
107
+ import { pcoUrl, pcoApiUrl } from "@planningcenter/url";
108
+
109
+ pcoUrl("people"); // https://people.planningcenteronline.com
110
+ pcoApiUrl("people"); // https://{app}.planningcenteronline.com/~api/people/v2
111
+ ```
112
+
113
+ ## `inferEnv`
114
+
115
+ The `inferEnv` `pcoUrl` and `pcoApiUrl` use is exported, should you need it.
116
+
117
+ ## Legacy
118
+
119
+ In `@planningcenter/url` versions <= 2.7.2, the default export was a function that took the `env` as an argument and returned a curried function for generating urls. That's still available, but its use is discouraged.
120
+
121
+ ### Examples
122
+
123
+ ```js
124
+ import planningcenterurl from "@planningcenter/url";
125
+
126
+ planningcenterurl("development")("api");
127
+ // => "http://api.pco.test"
74
128
 
75
- pcurl(railsEnv)("api");
129
+ planningcenterurl("staging")("people");
130
+ // => "https://accounts.planningcenteronline.com"
131
+
132
+ planningcenterurl("production")("accounts");
133
+ // => "https://people-staging.planningcenteronline.com"
134
+ ```
135
+
136
+ Arguments are curried. You can make a generic env-considered function.
137
+
138
+ ```js
139
+ const envURL = planningcenterurl(window.railsEnv);
140
+
141
+ envURL("api");
76
142
  ```
package/dist/index.d.ts CHANGED
@@ -1,4 +1,12 @@
1
- export declare type Environment = "production" | "staging" | "development" | "test" | "prototype";
2
- export declare type Product = "api" | "accounts" | "calendar" | "check-ins" | "giving" | "groups" | "login" | "people" | "publishing" | "registrations" | "services";
3
- declare const _default: (env: Environment) => (productName: Product) => string;
4
- export default _default;
1
+ export type Environment = "production" | "staging" | "development" | "test" | "prototype";
2
+ export type Product = "api" | "accounts" | "calendar" | "check-ins" | "giving" | "groups" | "home" | "login" | "people" | "publishing" | "registrations" | "services";
3
+ declare const legacy: (env: Environment) => (productName: Product) => string;
4
+ export default legacy;
5
+ export declare function pcoUrl(product: Product, { env }?: {
6
+ env?: Environment;
7
+ }): string;
8
+ export declare function pcoApiUrl(product: Product, { env, squiggly, }?: {
9
+ env?: Environment;
10
+ squiggly?: boolean;
11
+ }): string;
12
+ export declare const inferEnvironment: () => "production" | "staging" | "development" | "prototype";
package/dist/url.js CHANGED
@@ -1,2 +1,2 @@
1
- var t=function(){var t=location.hostname.match(/planningcenter(online)?.com/);return null===t?"planningcenteronline.com":t[0]};module.exports=function(n){return function(e){if(n&&e)switch(n){case"production":return"https://"+e+"."+t();case"staging":return"https://"+e+"-staging."+t();case"development":var o="test";try{o=location.hostname.match(/\pco\.(\w+)$/)[1]}catch(t){"localhost"!==location.hostname&&console.error(location.hostname+" is not a supported dev TLD")}return"http://"+e+".pco."+o;case"prototype":return"https://"+((r=null==(a=location)||null==(c=a.hostname)?void 0:c.match(/(?:www\.)?(.+)\..+\.planningcenter\.ninja/))&&"localhost"!==r[1]?r[1]:"main")+"."+e+".planningcenter.ninja";case"test":return"http://"+e+".pco.test";default:return"http://"+e+"."+t()}var a,c,r}};
1
+ var n=function(n){return function(t){if(n&&t)switch(n){case"production":return"https://"+t+"."+o();case"staging":return"https://"+t+"-staging."+o();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")}return"http://"+t+".pco."+i;case"prototype":return"https://"+e()+"."+t+".planningcenter.ninja";case"test":return"http://"+t+".pco.test";default:return"http://"+t+"."+o()}}},t=function(){var n=window.location.origin;return 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"},e=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"},o=function(){var n=location.hostname.match(/planningcenter(online)?.com/);return null===n?"planningcenteronline.com":n[0]};exports.default=n,exports.inferEnvironment=t,exports.pcoApiUrl=function(e,o){var i,c,r=void 0===o?{}:o,a=r.env,s=void 0===a?t():a,h=r.squiggly,p=void 0===h||h,l=p?"/~api":"";return l+="/"+e+"/v2",n(s)(p?(void 0===i&&(i=1),(c=window.location.hostname.split(".").slice(0,-1*(1+i)))["prototype"===t()?c.length-1:0].replace(/-staging$/,"")):"api")+l},exports.pcoUrl=function(e,o){var i=(void 0===o?{}:o).env,c=void 0===i?t():i;return n(c)(e)};
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 = \"production\" | \"staging\" | \"development\" | \"test\" | \"prototype\"\nexport type Product =\n | \"api\"\n | \"accounts\"\n | \"calendar\"\n | \"check-ins\"\n | \"giving\"\n | \"groups\"\n | \"login\"\n | \"people\"\n | \"publishing\"\n | \"registrations\"\n | \"services\"\n\nexport default (env: Environment) => (productName: Product) => {\n if (!(env && productName)) return\n\n switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${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 return `http://${productName}.pco.${tld}`\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\":\n return `http://${productName}.pco.test`\n default:\n return `http://${productName}.${domain()}`\n }\n}\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(/(?:www\\.)?(.+)\\..+\\.planningcenter\\.ninja/)\n\n if (result && result[1] !== \"localhost\") {\n return result[1]\n }\n\n return \"main\"\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"],"names":["domain","result","location","hostname","match","env","productName","tld","error","console","prototypeEnv","_location","_location$hostname"],"mappings":"AAcA,IA6CMA,EAAS,WACb,IAAMC,EAASC,SAASC,SAASC,MAAM,+BAEvC,OAAe,OAAXH,EACK,2BAEAA,EAAO,EAEjB,iBArDc,SAACI,GAAqB,OAAA,SAACC,GACpC,GAAMD,GAAOC,EAEb,OAAQD,GACN,IAAK,aACH,MAAkBC,WAAAA,MAAeN,IACnC,IAAK,UACH,MAAkBM,WAAAA,cAAuBN,IAC3C,IAAK,cACH,IAAIO,EAAM,OAEV,IACEA,EAAML,SAASC,SAASC,MAAM,gBAAgB,EAM/C,CALC,MAAOI,GAEmB,cAAtBN,SAASC,UACXM,QAAQD,MAASN,SAASC,uCAE7B,CAED,MAAiBG,UAAAA,EAAmBC,QAAAA,EACtC,IAAK,YACH,MAAkBG,aAchBT,SAASC,EAAAA,oBAAAS,EAAUR,iBAAVS,EAAoBR,MAAM,+CAEb,cAAdH,EAAO,GACZA,EAAO,GAGT,QApBiCK,IAAAA,EACtC,wBAAA,IAAK,OACH,gBAAiBA,EAAjB,YACF,QACE,MAAiBA,UAAAA,MAAeN,IASjB,IAAKW,EAAAC,EAClBX,CARP,CA5BD"}
1
+ {"version":3,"file":"url.js","sources":["../index.ts"],"sourcesContent":["export type Environment =\n | \"production\"\n | \"staging\"\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 switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${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 return `http://${productName}.pco.${tld}`\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\":\n return `http://${productName}.pco.test`\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\nexport const inferEnvironment = () => {\n const origin = window.location.origin\n\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 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$/, \"\")\n}\n"],"names":["legacy","env","productName","domain","tld","location","hostname","match","error","console","prototypeEnv","inferEnvironment","origin","window","endsWith","_location","_location$hostname","result","product","_temp2","tldLength","subdomains","_ref2","_ref2$env","squiggly","_ref2$squiggly","path","split","slice","length","replace","pcoUrl","_temp","_ref$env"],"mappings":"AAqBMA,IAAAA,EAAS,SAACC,GAAqB,OAAA,SAACC,GACpC,GAAMD,GAAOC,EAEb,OAAQD,GACN,IAAK,aACH,MAAkBC,WAAAA,MAAeC,IACnC,IAAK,UACH,MAAkBD,WAAAA,EAAuBC,YAAAA,IAC3C,IAAK,cACH,IAAIC,EAAM,OAEV,IACEA,EAAMC,SAASC,SAASC,MAAM,gBAAgB,EAM/C,CALC,MAAOC,GAEmB,cAAtBH,SAASC,UACXG,QAAQD,MAASH,SAASC,SAC3B,8BACF,CAED,MAAA,UAAiBJ,EAAjB,QAAoCE,EACtC,IAAK,YACH,MAAA,WAAkBM,IAAlB,IAAoCR,EAApC,wBACF,IAAK,OACH,MAAA,UAAiBA,EAAjB,YACF,QACE,MAAA,UAAiBA,EAAjB,IAAgCC,IAErC,CA5Bc,EAoDFQ,EAAmB,WAC9B,IAAMC,EAASC,OAAOR,SAASO,OAE/B,OAAIA,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,EAMKJ,EAAe,WAAK,IAAAK,EAAAC,EAClBC,EAAM,OAAAF,EAAGV,kBAAHW,EAAGD,EAAUT,eAAb,EAAGU,EAAoBT,MACjC,6CAGF,OAAIU,GAAwB,cAAdA,EAAO,GACZA,EAAO,GAGT,MACR,EAEKd,EAAS,WACb,IAAMc,EAASZ,SAASC,SAASC,MAAM,+BAEvC,OAAe,OAAXU,EACK,2BAEAA,EAAO,EAEjB,iEAzDe,SACdC,EAIiDC,GAAA,IAsDdC,EAK7BC,EA3D2CC,OAAA,IAAAH,EAAF,CAAE,EAAAA,EAAAI,EAAAD,EAF/CrB,IAAAA,OAE+C,IAAAsB,EAFzCZ,UACNa,SAAAA,OAC+C,IAAAC,GAAAA,EAE7CC,EAAOF,EAAW,QAAU,GAGhC,OAFAE,GAAYR,IAAAA,EAAZ,MAEOlB,EAAOC,EAAPD,CAAYwB,QAiDiC,IAAjBJ,IAAAA,EAAY,IAKzCC,EAAmCR,OAAOR,SAASC,SAJ7CqB,MAAM,KAAKC,MAAM,GAAsB,GAAlB,EAAIR,KAOZ,cAAvBT,IAAqCU,EAAWQ,OAAS,EAAI,GAC7DC,QAAQ,YAAa,KA1DwB,OAASJ,CACzD,iBAlBeK,SACdb,EADIc,GAEkD,YAAA,IAAAA,EAAA,CAAA,KAApD/B,IAAAA,OAAsD,IAAAgC,EAAhDtB,IAERsB,EAAA,OAAOjC,EAAOC,EAAPD,CAAYkB,EACpB"}
@@ -1,2 +1,2 @@
1
- var t=t=>o=>{if(t&&o)switch(t){case"production":return`https://${o}.${e()}`;case"staging":return`https://${o}-staging.${e()}`;case"development":let t="test";try{t=location.hostname.match(/\pco\.(\w+)$/)[1]}catch(t){"localhost"!==location.hostname&&console.error(`${location.hostname} is not a supported dev TLD`)}return`http://${o}.pco.${t}`;case"prototype":return`https://${n()}.${o}.planningcenter.ninja`;case"test":return`http://${o}.pco.test`;default:return`http://${o}.${e()}`}};const n=()=>{var t,n;const e=null==(t=location)||null==(n=t.hostname)?void 0:n.match(/(?:www\.)?(.+)\..+\.planningcenter\.ninja/);return e&&"localhost"!==e[1]?e[1]:"main"},e=()=>{const t=location.hostname.match(/planningcenter(online)?.com/);return null===t?"planningcenteronline.com":t[0]};export{t as default};
1
+ const n=n=>t=>{if(n&&t)switch(n){case"production":return`https://${t}.${i()}`;case"staging":return`https://${t}-staging.${i()}`;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`)}return`http://${t}.pco.${n}`;case"prototype":return`https://${c()}.${t}.planningcenter.ninja`;case"test":return`http://${t}.pco.test`;default:return`http://${t}.${i()}`}};function t(t,{env:e=o()}={}){return n(e)(t)}function e(t,{env:e=o(),squiggly:c=!0}={}){let i=c?"/~api":"";return i+=`/${t}/v2`,n(e)(c?r():"api")+i}const o=()=>{const n=window.location.origin;return 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=()=>{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"},i=()=>{const n=location.hostname.match(/planningcenter(online)?.com/);return null===n?"planningcenteronline.com":n[0]},r=()=>{const n=((n,t=1)=>window.location.hostname.split(".").slice(0,-1*(1+t)))();return n["prototype"===o()?n.length-1:0].replace(/-staging$/,"")};export{n as default,o 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 = \"production\" | \"staging\" | \"development\" | \"test\" | \"prototype\"\nexport type Product =\n | \"api\"\n | \"accounts\"\n | \"calendar\"\n | \"check-ins\"\n | \"giving\"\n | \"groups\"\n | \"login\"\n | \"people\"\n | \"publishing\"\n | \"registrations\"\n | \"services\"\n\nexport default (env: Environment) => (productName: Product) => {\n if (!(env && productName)) return\n\n switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${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 return `http://${productName}.pco.${tld}`\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\":\n return `http://${productName}.pco.test`\n default:\n return `http://${productName}.${domain()}`\n }\n}\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(/(?:www\\.)?(.+)\\..+\\.planningcenter\\.ninja/)\n\n if (result && result[1] !== \"localhost\") {\n return result[1]\n }\n\n return \"main\"\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"],"names":["index","env","productName","domain","tld","location","hostname","match","error","console","prototypeEnv","_location","_location$hostname","result"],"mappings":"AAcA,IAAAA,EAAgBC,GAAsBC,IACpC,GAAMD,GAAOC,EAEb,OAAQD,GACN,IAAK,aACH,iBAAkBC,KAAeC,MACnC,IAAK,UACH,iBAAkBD,aAAuBC,MAC3C,IAAK,cACH,IAAIC,EAAM,OAEV,IACEA,EAAMC,SAASC,SAASC,MAAM,gBAAgB,EAM/C,CALC,MAAOC,GAEmB,cAAtBH,SAASC,UACXG,QAAQD,MAAM,GAAGH,SAASC,sCAE7B,CAED,MAAiB,UAAAJ,SAAmBE,IACtC,IAAK,YACH,iBAAkBM,OAAkBR,yBACtC,IAAK,OACH,MAAO,UAAUA,aACnB,QACE,gBAAiBA,KAAeC,MAvBpC,EAgCF,MAAMO,EAAe,KACnB,IAAAC,EAAAC,EAAA,MAAMC,EAAS,OAAHF,EAAGN,WAAH,OAAGO,EAAAD,EAAUL,eAAV,EAAAM,EAAoBL,MAAM,6CAEzC,OAAIM,GAAwB,cAAdA,EAAO,GACZA,EAAO,GAGT,QAGHV,EAAS,KACb,MAAMU,EAASR,SAASC,SAASC,MAAM,+BAEvC,OAAe,OAAXM,EACK,2BAEAA,EAAO,EACf"}
1
+ {"version":3,"file":"url.modern.js","sources":["../index.ts"],"sourcesContent":["export type Environment =\n | \"production\"\n | \"staging\"\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 switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${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 return `http://${productName}.pco.${tld}`\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\":\n return `http://${productName}.pco.test`\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\nexport const inferEnvironment = () => {\n const origin = window.location.origin\n\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 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$/, \"\")\n}\n"],"names":["legacy","env","productName","domain","tld","location","hostname","match","error","console","prototypeEnv","pcoUrl","product","inferEnvironment","pcoApiUrl","squiggly","path","inferProduct","origin","window","endsWith","result","_location","_location$hostname","subdomains","host","tldLength","split","slice","extractSubdomainsFrom","length","replace"],"mappings":"AAqBMA,MAAAA,EAAUC,GAAsBC,IACpC,GAAMD,GAAOC,EAEb,OAAQD,GACN,IAAK,aACH,iBAAkBC,KAAeC,MACnC,IAAK,UACH,iBAAkBD,aAAuBC,MAC3C,IAAK,cACH,IAAIC,EAAM,OAEV,IACEA,EAAMC,SAASC,SAASC,MAAM,gBAAgB,EAM/C,CALC,MAAOC,GAEmB,cAAtBH,SAASC,UACXG,QAAQD,MAAM,GAAGH,SAASC,sCAE7B,CAED,MAAiB,UAAAJ,SAAmBE,IACtC,IAAK,YACH,iBAAkBM,OAAkBR,yBACtC,IAAK,OACH,MAAO,UAAUA,aACnB,QACE,gBAAiBA,KAAeC,MAvBpC,EA6BI,SAAUQ,EACdC,GACAX,IAAEA,EAAMY,KAA8C,CAAA,GAEtD,OAAOb,EAAOC,EAAPD,CAAYY,EACpB,CAEe,SAAAE,EACdF,GACAX,IACEA,EAAMY,IADRE,SAEEA,GAAW,GACkC,CALjC,GAOd,IAAIC,EAAOD,EAAW,QAAU,GAGhC,OAFAC,GAAQ,IAAIJ,OAELZ,EAAOC,EAAPD,CAAYe,EAAWE,IAAiB,OAASD,CACzD,CAEYH,MAAAA,EAAmB,KAC9B,MAAMK,EAASC,OAAOd,SAASa,OAE/B,OAAIA,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,cAOHV,EAAe,aACnB,MAAMW,EAAM,OAAAC,EAAGjB,WAAA,OAAHkB,EAAGD,EAAUhB,eAAb,EAAGiB,EAAoBhB,MACjC,6CAGF,OAAIc,GAAwB,cAAdA,EAAO,GACZA,EAAO,GAGT,QAGHlB,EAAS,KACb,MAAMkB,EAAShB,SAASC,SAASC,MAAM,+BAEvC,OAAe,OAAXc,EACK,2BAEAA,EAAO,EACf,EAOGJ,EAAe,KACnB,MAAMO,EALsB,EAACC,EAAMC,EAAY,IAKNP,OAAOd,SAASC,SAJ7CqB,MAAM,KAAKC,MAAM,GAAsB,GAAlB,EAAIF,IAIlBG,GAEnB,OAAOL,EACkB,cAAvBX,IAAqCW,EAAWM,OAAS,EAAI,GAC7DC,QAAQ,YAAa,GAFhB"}
@@ -1,2 +1,2 @@
1
- var t=function(t){return function(o){if(t&&o)switch(t){case"production":return"https://"+o+"."+e();case"staging":return"https://"+o+"-staging."+e();case"development":var a="test";try{a=location.hostname.match(/\pco\.(\w+)$/)[1]}catch(t){"localhost"!==location.hostname&&console.error(location.hostname+" is not a supported dev TLD")}return"http://"+o+".pco."+a;case"prototype":return"https://"+n()+"."+o+".planningcenter.ninja";case"test":return"http://"+o+".pco.test";default:return"http://"+o+"."+e()}}},n=function(){var t,n,e=null==(t=location)||null==(n=t.hostname)?void 0:n.match(/(?:www\.)?(.+)\..+\.planningcenter\.ninja/);return e&&"localhost"!==e[1]?e[1]:"main"},e=function(){var t=location.hostname.match(/planningcenter(online)?.com/);return null===t?"planningcenteronline.com":t[0]};export{t as default};
1
+ var n=function(n){return function(t){if(n&&t)switch(n){case"production":return"https://"+t+"."+i();case"staging":return"https://"+t+"-staging."+i();case"development":var e="test";try{e=location.hostname.match(/\pco\.(\w+)$/)[1]}catch(n){"localhost"!==location.hostname&&console.error(location.hostname+" is not a supported dev TLD")}return"http://"+t+".pco."+e;case"prototype":return"https://"+c()+"."+t+".planningcenter.ninja";case"test":return"http://"+t+".pco.test";default:return"http://"+t+"."+i()}}};function t(t,e){var c=(void 0===e?{}:e).env,i=void 0===c?o():c;return n(i)(t)}function e(t,e){var c=void 0===e?{}:e,i=c.env,a=void 0===i?o():i,s=c.squiggly,h=void 0===s||s,l=h?"/~api":"";return l+="/"+t+"/v2",n(a)(h?r():"api")+l}var o=function(){var n=window.location.origin;return 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"},i=function(){var n=location.hostname.match(/planningcenter(online)?.com/);return null===n?"planningcenteronline.com":n[0]},r=function(){var n,t=(void 0===n&&(n=1),window.location.hostname.split(".").slice(0,-1*(1+n)));return t["prototype"===o()?t.length-1:0].replace(/-staging$/,"")};export{n as default,o 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 = \"production\" | \"staging\" | \"development\" | \"test\" | \"prototype\"\nexport type Product =\n | \"api\"\n | \"accounts\"\n | \"calendar\"\n | \"check-ins\"\n | \"giving\"\n | \"groups\"\n | \"login\"\n | \"people\"\n | \"publishing\"\n | \"registrations\"\n | \"services\"\n\nexport default (env: Environment) => (productName: Product) => {\n if (!(env && productName)) return\n\n switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${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 return `http://${productName}.pco.${tld}`\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\":\n return `http://${productName}.pco.test`\n default:\n return `http://${productName}.${domain()}`\n }\n}\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(/(?:www\\.)?(.+)\\..+\\.planningcenter\\.ninja/)\n\n if (result && result[1] !== \"localhost\") {\n return result[1]\n }\n\n return \"main\"\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"],"names":["index","env","productName","domain","tld","location","hostname","match","error","console","prototypeEnv","_location","_location$hostname","result"],"mappings":"AAcA,IAAeA,EAAA,SAACC,GAAqB,OAAA,SAACC,GACpC,GAAMD,GAAOC,EAEb,OAAQD,GACN,IAAK,aACH,MAAkBC,WAAAA,MAAeC,IACnC,IAAK,UACH,MAAkBD,WAAAA,cAAuBC,IAC3C,IAAK,cACH,IAAIC,EAAM,OAEV,IACEA,EAAMC,SAASC,SAASC,MAAM,gBAAgB,EAM/C,CALC,MAAOC,GAEmB,cAAtBH,SAASC,UACXG,QAAQD,MAASH,SAASC,uCAE7B,CAED,MAAiBJ,UAAAA,EAAmBE,QAAAA,EACtC,IAAK,YACH,MAAkBM,WAAAA,IAAkBR,IAAAA,EACtC,wBAAA,IAAK,OACH,gBAAiBA,EAAjB,YACF,QACE,MAAiBA,UAAAA,MAAeC,IAErC,CA5BD,EAmCMO,EAAe,WAAK,IAAAC,EAAAC,EAClBC,SAASR,EAAAA,oBAAAM,EAAUL,iBAAVM,EAAoBL,MAAM,6CAEzC,OAAIM,GAAwB,cAAdA,EAAO,GACZA,EAAO,GAGT,MACR,EAEKV,EAAS,WACb,IAAMU,EAASR,SAASC,SAASC,MAAM,+BAEvC,OAAe,OAAXM,EACK,2BAEAA,EAAO,EAEjB"}
1
+ {"version":3,"file":"url.module.js","sources":["../index.ts"],"sourcesContent":["export type Environment =\n | \"production\"\n | \"staging\"\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 switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${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 return `http://${productName}.pco.${tld}`\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\":\n return `http://${productName}.pco.test`\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\nexport const inferEnvironment = () => {\n const origin = window.location.origin\n\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 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$/, \"\")\n}\n"],"names":["legacy","env","productName","domain","tld","location","hostname","match","error","console","prototypeEnv","pcoUrl","product","_temp","_ref$env","inferEnvironment","pcoApiUrl","_temp2","_ref2","_ref2$env","squiggly","_ref2$squiggly","path","inferProduct","origin","window","endsWith","_location","_location$hostname","result","tldLength","subdomains","split","slice","length","replace"],"mappings":"AAqBMA,IAAAA,EAAS,SAACC,GAAqB,OAAA,SAACC,GACpC,GAAMD,GAAOC,EAEb,OAAQD,GACN,IAAK,aACH,MAAkBC,WAAAA,MAAeC,IACnC,IAAK,UACH,MAAkBD,WAAAA,EAAuBC,YAAAA,IAC3C,IAAK,cACH,IAAIC,EAAM,OAEV,IACEA,EAAMC,SAASC,SAASC,MAAM,gBAAgB,EAM/C,CALC,MAAOC,GAEmB,cAAtBH,SAASC,UACXG,QAAQD,MAASH,SAASC,SAC3B,8BACF,CAED,MAAA,UAAiBJ,EAAjB,QAAoCE,EACtC,IAAK,YACH,MAAA,WAAkBM,IAAlB,IAAoCR,EAApC,wBACF,IAAK,OACH,MAAA,UAAiBA,EAAjB,YACF,QACE,MAAA,UAAiBA,EAAjB,IAAgCC,IAErC,CA5Bc,EAgCCQ,SAAAA,EACdC,EADIC,GAEkD,YAAA,IAAAA,EAAA,CAAA,KAApDZ,IAAAA,OAAsD,IAAAa,EAAhDC,IAERD,EAAA,OAAOd,EAAOC,EAAPD,CAAYY,EACpB,CAEe,SAAAI,EACdJ,EAIiDK,GAAA,IAAAC,OAAA,IAAAD,EAAF,CAAE,EAAAA,EAAAE,EAAAD,EAF/CjB,IAAAA,OAE+C,IAAAkB,EAFzCJ,UACNK,SAAAA,OAC+C,IAAAC,GAAAA,EAE7CC,EAAOF,EAAW,QAAU,GAGhC,OAFAE,GAAYV,IAAAA,EAAZ,MAEOZ,EAAOC,EAAPD,CAAYoB,EAAWG,IAAiB,OAASD,CACzD,CAEYP,IAAAA,EAAmB,WAC9B,IAAMS,EAASC,OAAOpB,SAASmB,OAE/B,OAAIA,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,OAAAF,EAAGtB,kBAAHuB,EAAGD,EAAUrB,eAAb,EAAGsB,EAAoBrB,MACjC,6CAGF,OAAIsB,GAAwB,cAAdA,EAAO,GACZA,EAAO,GAGT,MACR,EAEK1B,EAAS,WACb,IAAM0B,EAASxB,SAASC,SAASC,MAAM,+BAEvC,OAAe,OAAXsB,EACK,2BAEAA,EAAO,EAEjB,EAMKN,EAAe,WACnB,IALmCO,EAK7BC,QAL8C,IAAjBD,IAAAA,EAAY,GAKNL,OAAOpB,SAASC,SAJ7C0B,MAAM,KAAKC,MAAM,GAAsB,GAAlB,EAAIH,KAMrC,OAAOC,EACkB,cAAvBhB,IAAqCgB,EAAWG,OAAS,EAAI,GAC7DC,QAAQ,YAAa,GACxB"}
package/dist/url.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((n||self).PLANNINGCENTER=n.PLANNINGCENTER||{},n.PLANNINGCENTER.url=t())}(this,function(){var n=function(){var n=location.hostname.match(/planningcenter(online)?.com/);return null===n?"planningcenteronline.com":n[0]};return function(t){return function(e){if(t&&e)switch(t){case"production":return"https://"+e+"."+n();case"staging":return"https://"+e+"-staging."+n();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")}return"http://"+e+".pco."+o;case"prototype":return"https://"+((r=null==(a=location)||null==(c=a.hostname)?void 0:c.match(/(?:www\.)?(.+)\..+\.planningcenter\.ninja/))&&"localhost"!==r[1]?r[1]:"main")+"."+e+".planningcenter.ninja";case"test":return"http://"+e+".pco.test";default:return"http://"+e+"."+n()}var a,c,r}}});
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)switch(n){case"production":return"https://"+t+"."+i();case"staging":return"https://"+t+"-staging."+i();case"development":var e="test";try{e=location.hostname.match(/\pco\.(\w+)$/)[1]}catch(n){"localhost"!==location.hostname&&console.error(location.hostname+" is not a supported dev TLD")}return"http://"+t+".pco."+e;case"prototype":return"https://"+o()+"."+t+".planningcenter.ninja";case"test":return"http://"+t+".pco.test";default:return"http://"+t+"."+i()}}},e=function(){var n=window.location.origin;return 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(){var n=location.hostname.match(/planningcenter(online)?.com/);return null===n?"planningcenteronline.com":n[0]};n.default=t,n.inferEnvironment=e,n.pcoApiUrl=function(n,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+="/"+n+"/v2",t(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$/,"")):"api")+p},n.pcoUrl=function(n,o){var i=(void 0===o?{}:o).env,c=void 0===i?e():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 = \"production\" | \"staging\" | \"development\" | \"test\" | \"prototype\"\nexport type Product =\n | \"api\"\n | \"accounts\"\n | \"calendar\"\n | \"check-ins\"\n | \"giving\"\n | \"groups\"\n | \"login\"\n | \"people\"\n | \"publishing\"\n | \"registrations\"\n | \"services\"\n\nexport default (env: Environment) => (productName: Product) => {\n if (!(env && productName)) return\n\n switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${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 return `http://${productName}.pco.${tld}`\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\":\n return `http://${productName}.pco.test`\n default:\n return `http://${productName}.${domain()}`\n }\n}\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(/(?:www\\.)?(.+)\\..+\\.planningcenter\\.ninja/)\n\n if (result && result[1] !== \"localhost\") {\n return result[1]\n }\n\n return \"main\"\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"],"names":["domain","result","location","hostname","match","env","productName","tld","error","console","prototypeEnv","_location","_location$hostname"],"mappings":"6QAce,IA6CTA,EAAS,WACb,IAAMC,EAASC,SAASC,SAASC,MAAM,+BAEvC,OAAe,OAAXH,EACK,2BAEAA,EAAO,EAEjB,SArDc,SAACI,GAAqB,OAAA,SAACC,GACpC,GAAMD,GAAOC,EAEb,OAAQD,GACN,IAAK,aACH,MAAkBC,WAAAA,MAAeN,IACnC,IAAK,UACH,MAAkBM,WAAAA,cAAuBN,IAC3C,IAAK,cACH,IAAIO,EAAM,OAEV,IACEA,EAAML,SAASC,SAASC,MAAM,gBAAgB,EAM/C,CALC,MAAOI,GAEmB,cAAtBN,SAASC,UACXM,QAAQD,MAASN,SAASC,uCAE7B,CAED,MAAiBG,UAAAA,EAAmBC,QAAAA,EACtC,IAAK,YACH,MAAkBG,aAchBT,SAASC,EAAAA,oBAAAS,EAAUR,iBAAVS,EAAoBR,MAAM,+CAEb,cAAdH,EAAO,GACZA,EAAO,GAGT,QApBiCK,IAAAA,EACtC,wBAAA,IAAK,OACH,gBAAiBA,EAAjB,YACF,QACE,MAAiBA,UAAAA,MAAeN,IASjB,IAAKW,EAAAC,EAClBX,CARP,CA5BD"}
1
+ {"version":3,"file":"url.umd.js","sources":["../index.ts"],"sourcesContent":["export type Environment =\n | \"production\"\n | \"staging\"\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 switch (env) {\n case \"production\":\n return `https://${productName}.${domain()}`\n case \"staging\":\n return `https://${productName}-staging.${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 return `http://${productName}.pco.${tld}`\n case \"prototype\":\n return `https://${prototypeEnv()}.${productName}.planningcenter.ninja`\n case \"test\":\n return `http://${productName}.pco.test`\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\nexport const inferEnvironment = () => {\n const origin = window.location.origin\n\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 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$/, \"\")\n}\n"],"names":["legacy","env","productName","domain","tld","location","hostname","match","error","console","prototypeEnv","inferEnvironment","origin","window","endsWith","_location","_location$hostname","result","product","_temp2","tldLength","subdomains","_ref2","_ref2$env","squiggly","_ref2$squiggly","path","split","slice","length","replace","pcoUrl","_temp","_ref$env"],"mappings":"oRAqBMA,IAAAA,EAAS,SAACC,GAAqB,OAAA,SAACC,GACpC,GAAMD,GAAOC,EAEb,OAAQD,GACN,IAAK,aACH,MAAkBC,WAAAA,MAAeC,IACnC,IAAK,UACH,MAAkBD,WAAAA,EAAuBC,YAAAA,IAC3C,IAAK,cACH,IAAIC,EAAM,OAEV,IACEA,EAAMC,SAASC,SAASC,MAAM,gBAAgB,EAM/C,CALC,MAAOC,GAEmB,cAAtBH,SAASC,UACXG,QAAQD,MAASH,SAASC,SAC3B,8BACF,CAED,MAAA,UAAiBJ,EAAjB,QAAoCE,EACtC,IAAK,YACH,MAAA,WAAkBM,IAAlB,IAAoCR,EAApC,wBACF,IAAK,OACH,MAAA,UAAiBA,EAAjB,YACF,QACE,MAAA,UAAiBA,EAAjB,IAAgCC,IAErC,CA5Bc,EAoDFQ,EAAmB,WAC9B,IAAMC,EAASC,OAAOR,SAASO,OAE/B,OAAIA,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,EAMKJ,EAAe,WAAK,IAAAK,EAAAC,EAClBC,EAAM,OAAAF,EAAGV,kBAAHW,EAAGD,EAAUT,eAAb,EAAGU,EAAoBT,MACjC,6CAGF,OAAIU,GAAwB,cAAdA,EAAO,GACZA,EAAO,GAGT,MACR,EAEKd,EAAS,WACb,IAAMc,EAASZ,SAASC,SAASC,MAAM,+BAEvC,OAAe,OAAXU,EACK,2BAEAA,EAAO,EAEjB,+CAzDe,SACdC,EAIiDC,GAAA,IAsDdC,EAK7BC,EA3D2CC,OAAA,IAAAH,EAAF,CAAE,EAAAA,EAAAI,EAAAD,EAF/CrB,IAAAA,OAE+C,IAAAsB,EAFzCZ,UACNa,SAAAA,OAC+C,IAAAC,GAAAA,EAE7CC,EAAOF,EAAW,QAAU,GAGhC,OAFAE,GAAYR,IAAAA,EAAZ,MAEOlB,EAAOC,EAAPD,CAAYwB,QAiDiC,IAAjBJ,IAAAA,EAAY,IAKzCC,EAAmCR,OAAOR,SAASC,SAJ7CqB,MAAM,KAAKC,MAAM,GAAsB,GAAlB,EAAIR,KAOZ,cAAvBT,IAAqCU,EAAWQ,OAAS,EAAI,GAC7DC,QAAQ,YAAa,KA1DwB,OAASJ,CACzD,WAlBeK,SACdb,EADIc,GAEkD,YAAA,IAAAA,EAAA,CAAA,KAApD/B,IAAAA,OAAsD,IAAAgC,EAAhDtB,IAERsB,EAAA,OAAOjC,EAAOC,EAAPD,CAAYkB,EACpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planningcenter/url",
3
- "version": "2.7.2",
3
+ "version": "3.0.0-rc.0",
4
4
  "description": "url utilities for planning center apps",
5
5
  "source": "index.ts",
6
6
  "main": "./dist/url.js",
@@ -27,21 +27,22 @@
27
27
  "homepage": "https://github.com/planningcenter/url",
28
28
  "private": false,
29
29
  "devDependencies": {
30
- "@types/jest": "^27.4.1",
31
- "@typescript-eslint/eslint-plugin": "^5.20.0",
32
- "@typescript-eslint/parser": "^5.20.0",
33
- "eslint": "^8.13.0",
34
- "eslint-import-resolver-typescript": "^2.7.1",
35
- "eslint-plugin-import": "^2.26.0",
36
- "eslint-plugin-simple-import-sort": "^7.0.0",
30
+ "@types/jest": "^29.5.14",
31
+ "@typescript-eslint/eslint-plugin": "^8.29.0",
32
+ "@typescript-eslint/parser": "^8.29.0",
33
+ "eslint": "^9.23.0",
34
+ "eslint-import-resolver-typescript": "^4.3.1",
35
+ "eslint-plugin-import": "^2.31.0",
36
+ "eslint-plugin-simple-import-sort": "^12.1.1",
37
37
  "eslint-plugin-sort-keys-fix": "^1.1.2",
38
- "eslint-plugin-typescript-sort-keys": "^2.1.0",
39
- "jest": "^27.5.1",
40
- "microbundle": "^0.13.0",
41
- "prettier": "^2.6.2",
42
- "ts-jest": "^27.1.4",
43
- "ts-loader": "^9.2.8",
44
- "ts-node": "^10.7.0",
45
- "typescript": "^4.6.3"
38
+ "eslint-plugin-typescript-sort-keys": "^3.3.0",
39
+ "jest": "^29.7.0",
40
+ "jest-environment-jsdom": "^29.7.0",
41
+ "microbundle": "^0.15.1",
42
+ "prettier": "^3.5.3",
43
+ "ts-jest": "^29.3.1",
44
+ "ts-loader": "^9.5.2",
45
+ "ts-node": "^10.9.2",
46
+ "typescript": "^5.8.2"
46
47
  }
47
48
  }