@blueprint-sdk/app
Advanced tools
Comparing version 0.1.1 to 0.1.2
# @blueprint-sdk/app | ||
## 0.1.2 | ||
### Patch Changes | ||
- 875f7eb0: Add appkey check | ||
## 0.1.1 | ||
@@ -4,0 +10,0 @@ |
var __defProp = Object.defineProperty; | ||
var __typeError = (msg) => { | ||
throw TypeError(msg); | ||
}; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); | ||
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); | ||
/** | ||
@@ -20,17 +26,49 @@ * @license | ||
*/ | ||
function initializeApp(options) { | ||
return new BluePrintApp(options); | ||
var _keyPayload; | ||
function getApiUrl(env) { | ||
switch (env) { | ||
case "dev": | ||
return "https://api2-dev.sourcesync.io"; | ||
case "stg": | ||
return "https://api2-stg.sourcesync.io"; | ||
case "prod": | ||
return "https://api2.sourcesync.io"; | ||
default: | ||
return "https://api2.sourcesync.io"; | ||
} | ||
} | ||
class BluePrintApp { | ||
async function initializeApp(options) { | ||
const app = new BluePrintAppImpl(options); | ||
await app.verifyAppKey(); | ||
return app; | ||
} | ||
class BluePrintAppImpl { | ||
constructor(options) { | ||
__publicField(this, "options"); | ||
__publicField(this, "env"); | ||
__privateAdd(this, _keyPayload); | ||
this.options = options; | ||
this.env = options.env ?? "prod"; | ||
} | ||
async verifyAppKey() { | ||
const options = this.options; | ||
if (options.appKey == null) { | ||
throw new Error("App key is required"); | ||
} | ||
const result = await fetch( | ||
getApiUrl(this.env) + "/key", | ||
{ method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ key: options.appKey }) } | ||
); | ||
if (!result.ok) { | ||
console.error("Invalid app key", result.status, result.statusText, await result.text()); | ||
throw new Error("Invalid app key"); | ||
} | ||
__privateSet(this, _keyPayload, await result.json()); | ||
} | ||
} | ||
_keyPayload = new WeakMap(); | ||
export { | ||
BluePrintApp, | ||
BluePrintAppImpl, | ||
initializeApp | ||
}; | ||
//# sourceMappingURL=app.js.map |
@@ -1,5 +0,13 @@ | ||
export declare class BluePrintApp { | ||
export declare interface BluePrintApp { | ||
options: BluePrintAppOptions; | ||
readonly env: string; | ||
verifyAppKey: () => Promise<void>; | ||
} | ||
export declare class BluePrintAppImpl implements BluePrintApp { | ||
#private; | ||
options: BluePrintAppOptions; | ||
readonly env: string; | ||
constructor(options: BluePrintAppOptions); | ||
verifyAppKey(): Promise<void>; | ||
} | ||
@@ -26,6 +34,7 @@ | ||
organizationId?: string; | ||
appKey: string; | ||
} | ||
export declare function initializeApp(options: BluePrintAppOptions): BluePrintApp; | ||
export declare function initializeApp(options: BluePrintAppOptions): Promise<BluePrintApp>; | ||
export { } |
@@ -1,6 +0,6 @@ | ||
import { BluePrintApp, initializeApp } from "./app.js"; | ||
import { BluePrintAppImpl, initializeApp } from "./app.js"; | ||
export { | ||
BluePrintApp, | ||
BluePrintAppImpl, | ||
initializeApp | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@blueprint-sdk/app", | ||
"private": false, | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "author": "Source Digital <dev@sourcedigital.net>", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
27298
184
2