@parkingboss/api
Advanced tools
+2
-17
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.apiBase = void 0; | ||
| const BASE_LINK_QUERY = "link[rel~='index'][rel~='api'][type~='application/json']"; | ||
| function apiBaseLink() { | ||
| const link = document.querySelector(BASE_LINK_QUERY); | ||
| if (!link) { | ||
| throw new Error(`No <${BASE_LINK_QUERY}> found!`); | ||
| } | ||
| return link; | ||
| } | ||
| function apiBase() { | ||
| const link = apiBaseLink(); | ||
| const link = new URL("https://api.propertyboss.io/v2"); | ||
| return { | ||
| subscribe(fn) { | ||
| fn(link.href); | ||
| const observer = new MutationObserver(muts => { | ||
| muts.forEach(mut => { | ||
| if (mut.attributeName === 'href') | ||
| fn(link.href); | ||
| }); | ||
| }); | ||
| observer.observe(link, { attributes: true }); | ||
| return () => observer.disconnect(); | ||
| return () => { }; | ||
| }, | ||
@@ -26,0 +11,0 @@ set(val) { |
@@ -1,2 +0,1 @@ | ||
| import { BaseWatcher } from "./base"; | ||
| import { User } from "./loadUser"; | ||
@@ -14,3 +13,2 @@ import { SessionControl } from "./session"; | ||
| apiBase: string; | ||
| baseStore: BaseWatcher; | ||
| } | ||
@@ -17,0 +15,0 @@ export interface CoreApi { |
@@ -8,3 +8,2 @@ "use strict"; | ||
| function optsToSettings(opts) { | ||
| const baseStore = base_1.apiBase(); | ||
| const settings = { | ||
@@ -14,7 +13,7 @@ client: opts.client, | ||
| apiBase: opts.apiBase || "TEMP_FAKE", | ||
| baseStore, | ||
| }; | ||
| baseStore.subscribe((newBase) => { | ||
| settings.apiBase = opts.apiBase ?? newBase; | ||
| }); | ||
| if (!opts.apiBase) { | ||
| const watcher = base_1.apiBase(); | ||
| watcher.subscribe((newBase) => (settings.apiBase = newBase)); | ||
| } | ||
| return settings; | ||
@@ -21,0 +20,0 @@ } |
@@ -18,3 +18,3 @@ "use strict"; | ||
| const opts = maybeOpt || (isUrlLike(urlOrOpt) ? {} : urlOrOpt); | ||
| const url = new URL(urlArg.toString(), document.baseURI); | ||
| const url = new URL(urlArg.toString(), "https://api.propertyboss.io/v2"); | ||
| Object.entries(opts.query || {}).forEach(([key, val]) => { | ||
@@ -21,0 +21,0 @@ if (val) { |
+2
-17
@@ -1,22 +0,7 @@ | ||
| const BASE_LINK_QUERY = "link[rel~='index'][rel~='api'][type~='application/json']"; | ||
| function apiBaseLink() { | ||
| const link = document.querySelector(BASE_LINK_QUERY); | ||
| if (!link) { | ||
| throw new Error(`No <${BASE_LINK_QUERY}> found!`); | ||
| } | ||
| return link; | ||
| } | ||
| export function apiBase() { | ||
| const link = apiBaseLink(); | ||
| const link = new URL("https://api.propertyboss.io/v2"); | ||
| return { | ||
| subscribe(fn) { | ||
| fn(link.href); | ||
| const observer = new MutationObserver(muts => { | ||
| muts.forEach(mut => { | ||
| if (mut.attributeName === 'href') | ||
| fn(link.href); | ||
| }); | ||
| }); | ||
| observer.observe(link, { attributes: true }); | ||
| return () => observer.disconnect(); | ||
| return () => { }; | ||
| }, | ||
@@ -23,0 +8,0 @@ set(val) { |
@@ -1,2 +0,1 @@ | ||
| import { BaseWatcher } from "./base"; | ||
| import { User } from "./loadUser"; | ||
@@ -14,3 +13,2 @@ import { SessionControl } from "./session"; | ||
| apiBase: string; | ||
| baseStore: BaseWatcher; | ||
| } | ||
@@ -17,0 +15,0 @@ export interface CoreApi { |
@@ -5,3 +5,2 @@ import { apiBase } from "./base"; | ||
| function optsToSettings(opts) { | ||
| const baseStore = apiBase(); | ||
| const settings = { | ||
@@ -11,7 +10,7 @@ client: opts.client, | ||
| apiBase: opts.apiBase || "TEMP_FAKE", | ||
| baseStore, | ||
| }; | ||
| baseStore.subscribe((newBase) => { | ||
| settings.apiBase = opts.apiBase ?? newBase; | ||
| }); | ||
| if (!opts.apiBase) { | ||
| const watcher = apiBase(); | ||
| watcher.subscribe((newBase) => (settings.apiBase = newBase)); | ||
| } | ||
| return settings; | ||
@@ -18,0 +17,0 @@ } |
@@ -15,3 +15,3 @@ function urlToPath(url, opts = {}) { | ||
| const opts = maybeOpt || (isUrlLike(urlOrOpt) ? {} : urlOrOpt); | ||
| const url = new URL(urlArg.toString(), document.baseURI); | ||
| const url = new URL(urlArg.toString(), "https://api.propertyboss.io/v2"); | ||
| Object.entries(opts.query || {}).forEach(([key, val]) => { | ||
@@ -18,0 +18,0 @@ if (val) { |
+1
-1
| { | ||
| "name": "@parkingboss/api", | ||
| "version": "1.4.0", | ||
| "version": "2.0.0", | ||
| "description": "The Parking Boss API", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
+2
-5
@@ -1,2 +0,2 @@ | ||
| # Parking Boss API | ||
| # DEPRECATED: Parking Boss API | ||
@@ -7,3 +7,3 @@ This package adds managed access to the parking boss API. The API is relatively | ||
| ```typescript | ||
| ```ts | ||
| import { Api } from "@parkingboss/api"; | ||
@@ -19,4 +19,1 @@ | ||
| ``` | ||
| This package _expects_ to be run in a browser context. Refactoring for node has | ||
| is an open TODO. |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
44898
-2.84%1368
-2.56%18
-14.29%11
10%