@nicheprotocol/darwin-sdk
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "@nicheprotocol/darwin-sdk", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"main": "./dist/index.js", | ||
@@ -17,4 +17,6 @@ "types": "./dist/index.d.ts", | ||
"jest": "^29.4.2", | ||
"jest-environment-jsdom": "^29.4.2", | ||
"ts-jest": "^29.0.5", | ||
"typescript": "^4.9.5" | ||
"typescript": "^4.9.5", | ||
"whatwg-fetch": "^3.6.2" | ||
}, | ||
@@ -21,0 +23,0 @@ "dependencies": { |
@@ -1,2 +0,6 @@ | ||
export { createToken, verifyToken } from './token'; | ||
export { init } from './store'; | ||
import { createToken, verifyToken } from './token'; | ||
import { init } from './store'; | ||
export const server = { init, createToken, verifyToken }; | ||
export const client = {}; |
@@ -1,13 +0,35 @@ | ||
import { init as initKey, deinit as deinitKey } from './secret'; | ||
import { TOKEN_STORAGE_KEY } from './connect'; | ||
import { init as initKey, get as getKey } from './secret'; | ||
type DarwinInitialization = { | ||
type TStorage = { | ||
getItem(key: string): any; | ||
setItem(key: string, value: any): void; | ||
}; | ||
type DarwinState = { | ||
endpointUrl?: string; | ||
key: { | ||
fetchTokenRoute?: string; | ||
key?: { | ||
publicKey: string; | ||
secretKey?: string; | ||
}; | ||
storage: TStorage; | ||
}; | ||
export const init = ({ key }: DarwinInitialization) => { | ||
initKey(key.publicKey, key.secretKey); | ||
let url = ''; | ||
let tokenRoute = ''; | ||
let storageStrategy: TStorage; | ||
export const init = ({ endpointUrl, fetchTokenRoute, key, storage }: DarwinState) => { | ||
if (endpointUrl) { | ||
url = endpointUrl; | ||
} | ||
if (fetchTokenRoute) { | ||
tokenRoute = fetchTokenRoute; | ||
} | ||
if (key) { | ||
initKey(key.publicKey, key.secretKey); | ||
} | ||
storageStrategy = storage; | ||
}; | ||
@@ -17,4 +39,13 @@ | ||
export const get = () => { | ||
return {}; | ||
export const get = (): DarwinState => { | ||
return { | ||
endpointUrl: url, | ||
fetchTokenRoute: tokenRoute, | ||
key: getKey(), | ||
storage: storageStrategy, | ||
}; | ||
}; | ||
export const getToken = async (): Promise<string> => { | ||
return storageStrategy.getItem(TOKEN_STORAGE_KEY); | ||
}; |
import { sign, verify } from 'jsonwebtoken'; | ||
import { get } from './secret'; | ||
type DarwinTokenPayload = { | ||
export type DarwinTokenPayload = { | ||
/** | ||
* User id. | ||
*/ | ||
id: string; | ||
/** | ||
* User full name. | ||
*/ | ||
fullName: string; | ||
/** | ||
* Clubs this user is authorized to manage billing for. | ||
*/ | ||
authorizations: string[]; | ||
@@ -21,3 +30,5 @@ }; | ||
if (!key?.secretKey) { | ||
throw new Error(`Darwin not initialized with private key. Invoke init() first.`); | ||
throw new Error( | ||
`Darwin not initialized with private key. Invoke init() first.`, | ||
); | ||
} | ||
@@ -36,3 +47,5 @@ | ||
if (!key?.publicKey) { | ||
throw new Error(`Darwin not initialized with public key. Invoke init() first.`); | ||
throw new Error( | ||
`Darwin not initialized with public key. Invoke init() first.`, | ||
); | ||
} | ||
@@ -39,0 +52,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
411
11383
7
15
1