-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
6,771 additions
and
82 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"root": true, | ||
"ignorePatterns": [ | ||
"*.js", | ||
"*.d.ts", | ||
"node_modules/" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 2021, | ||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier | ||
], | ||
"rules": { | ||
"@typescript-eslint/no-explicit-any": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
tsconfig.json | ||
.jsii | ||
|
||
*.js | ||
*.d.ts | ||
|
||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Dependency directories | ||
node_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# default build output | ||
dist/ | ||
|
||
# Temporary folders | ||
tmp/ | ||
temp/ | ||
|
||
# Custom | ||
.idea/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm | ||
|
||
node_modules | ||
coverage | ||
.vscode | ||
.DS_Store | ||
.nyc_output | ||
.history | ||
.idea | ||
Thumbs.db | ||
|
||
|
||
# Exclude jsii outdir | ||
dist | ||
|
||
# Include .jsii and .jsii.gz | ||
!.jsii | ||
!.jsii.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## @affinidi-tdk/common | ||
|
||
### Build JSII | ||
|
||
``` | ||
npm i --prefix . | ||
npm run build | ||
npm run package | ||
``` | ||
|
||
The code will be generated under /dist for each language. | ||
|
||
### Usage | ||
|
||
### JS | ||
|
||
```bash | ||
npm install @affinidi-tdk/common | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
export enum Environment { | ||
LOCAL = 'local', | ||
DEVELOPMENT = 'dev', | ||
PRODUCTION = 'prod', | ||
} | ||
|
||
const DEFAULT_REGION = 'ap-southeast-1' | ||
|
||
const envToApiGwUrl = { | ||
[Environment.LOCAL]: 'https://apse1.dev.api.affinidi.io', | ||
[Environment.DEVELOPMENT]: 'https://apse1.dev.api.affinidi.io', | ||
[Environment.PRODUCTION]: 'https://apse1.api.affinidi.io', | ||
} | ||
|
||
const envToElementsAuthTokenUrl = { | ||
[Environment.LOCAL]: | ||
'https://apse1.dev.auth.developer.affinidi.io/auth/oauth2/token', | ||
[Environment.DEVELOPMENT]: | ||
'https://apse1.dev.auth.developer.affinidi.io/auth/oauth2/token', | ||
[Environment.PRODUCTION]: | ||
'https://apse1.auth.developer.affinidi.io/auth/oauth2/token', | ||
} | ||
|
||
const envToIotUrl = { | ||
[Environment.LOCAL]: 'a3sq1vuw0cw9an-ats.iot.ap-southeast-1.amazonaws.com', | ||
[Environment.DEVELOPMENT]: | ||
'a3sq1vuw0cw9an-ats.iot.ap-southeast-1.amazonaws.com', | ||
[Environment.PRODUCTION]: | ||
'a3sq1vuw0cw9an-ats.iot.ap-southeast-1.amazonaws.com', | ||
} | ||
|
||
export class EnvironmentUtils { | ||
static fetchEnvironment(): Environment { | ||
const backendEnv = process.env.AFFINIDI_TDK_ENVIRONMENT | ||
if (backendEnv) { | ||
return backendEnv as Environment | ||
} | ||
|
||
const nextPublicEnv = process.env.NEXT_PUBLIC_AFFINIDI_TDK_ENVIRONMENT | ||
if (nextPublicEnv) { | ||
return nextPublicEnv as Environment | ||
} | ||
|
||
return Environment.PRODUCTION | ||
} | ||
|
||
static fetchApiGwUrl(): string { | ||
const env = this.fetchEnvironment() | ||
return `${envToApiGwUrl[env]}` | ||
} | ||
|
||
static fetchElementsAuthTokenUrl(): string { | ||
const env = this.fetchEnvironment() | ||
return `${envToElementsAuthTokenUrl[env]}` | ||
} | ||
|
||
static fetchRegion(): string { | ||
return DEFAULT_REGION | ||
} | ||
|
||
static fetchIotUrl(): string { | ||
const env = this.fetchEnvironment() | ||
return `${envToIotUrl[env]}` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { Environment, EnvironmentUtils } from './environment' | ||
export { VaultUtils } from './vault' | ||
export { Logger } from './logger' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Environment, EnvironmentUtils } from './environment' | ||
|
||
export class Logger { | ||
private static isDebugEnabled: boolean = | ||
EnvironmentUtils.fetchEnvironment() !== Environment.PRODUCTION | ||
|
||
static debug(message: string, ...optionalParams: any[]): void { | ||
if (this.isDebugEnabled) { | ||
console.log(`TDK: ${message}`, ...optionalParams) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Environment, EnvironmentUtils } from './environment' | ||
|
||
const LOCAL_VAULT_URL = 'http://localhost:3001' | ||
const DEV_VAULT_URL = 'https://vault.dev.affinidi.com' | ||
const PROD_VAULT_URL = 'https://vault.affinidi.com' | ||
|
||
const envToWebVaultUrlMap = { | ||
[Environment.LOCAL]: LOCAL_VAULT_URL, | ||
[Environment.DEVELOPMENT]: DEV_VAULT_URL, | ||
[Environment.PRODUCTION]: PROD_VAULT_URL, | ||
} | ||
|
||
const SHARE_PATH = '/login' | ||
const CLAIM_PATH = '/claim' | ||
|
||
export class VaultUtils { | ||
static buildShareLink(request: string, client_id: string): string { | ||
const env = EnvironmentUtils.fetchEnvironment() | ||
const params = new URLSearchParams() | ||
params.append('request', request) | ||
params.append('client_id', client_id) | ||
const queryString = params.toString() | ||
return `${envToWebVaultUrlMap[env] || PROD_VAULT_URL}${SHARE_PATH}?${queryString}` | ||
} | ||
|
||
static buildClaimLink(credentialOfferUri: string): string { | ||
const env = EnvironmentUtils.fetchEnvironment() | ||
const params = new URLSearchParams() | ||
params.append('credential_offer_uri', credentialOfferUri) | ||
const queryString = params.toString() | ||
return `${envToWebVaultUrlMap[env] || PROD_VAULT_URL}${CLAIM_PATH}?${queryString}` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Environment, EnvironmentUtils, VaultUtils } from './helpers' |
Oops, something went wrong.