mirror of
https://github.com/openziti/zrok.git
synced 2025-02-02 03:20:26 +01:00
remove old initial js impl and replace with ts
This commit is contained in:
parent
ae8e7acf5e
commit
8bbd62718b
68
.github/workflows/node-sdk.yml
vendored
Normal file
68
.github/workflows/node-sdk.yml
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
name: Build/Relesae Node SDK
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [ published ]
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
name: Build for Node-${{ matrix.node_ver }} ${{ matrix.config.target }}/${{ matrix.config.arch }}
|
||||
runs-on: ${{ matrix.config.os }}
|
||||
|
||||
env:
|
||||
BUILD_NUMBER: ${{ github.run_number }}
|
||||
AWS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
config:
|
||||
- { os: windows-latest, target: "windows", arch: "x64" }
|
||||
- { os: ubuntu-20.04, target: "linux", arch: "x64" }
|
||||
- { os: ubuntu-20.04, target: "linux", arch: "arm64" }
|
||||
- { os: macos-latest, target: "macos", arch: "x64" }
|
||||
- { os: macos-latest, target: "macos", arch: "arm64" }
|
||||
node_ver: [ 16, 18, 19, 20, 21]
|
||||
fail-fast: false
|
||||
|
||||
steps:
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: 'recursive'
|
||||
|
||||
- name: Get crossbuild tools
|
||||
if: matrix.config.target == 'linux' && matrix.config.arch != 'x64'
|
||||
run: |
|
||||
sudo apt update -y
|
||||
sudo apt install -y crossbuild-essential-${{ matrix.config.arch }}
|
||||
|
||||
- name: Node Version
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node_ver }}
|
||||
|
||||
- name: Get current date
|
||||
id: date
|
||||
run: echo "date=$(date)" >> $GITHUB_OUTPUT
|
||||
|
||||
|
||||
- name: Build NodeJS-SDK
|
||||
run: |
|
||||
cd ${{ runner.workspace }}/${{ github.event.repository.name }}
|
||||
npm install
|
||||
npm run build:package -- --target_arch=${{ matrix.config.arch }}
|
||||
env:
|
||||
PRESET: ci-${{ matrix.config.target }}-${{ matrix.config.arch }}
|
||||
TARGET_ARCH: ${{ matrix.config.arch }}
|
||||
BUILD_DATE: ${{ steps.date.outputs.date }}
|
||||
|
||||
- name: NPM Publish
|
||||
uses: JS-DevTools/npm-publish@v1
|
||||
with:
|
||||
token: ${{ secrets.NPM_TOKEN }}
|
||||
access: public
|
||||
if: |
|
||||
matrix.config.os == 'ubuntu-20.04' && matrix.node_ver == '20' && matrix.config.arch == 'x64' && startsWith(github.ref, 'refs/tags/')
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -10,7 +10,7 @@ etc/dev-frontend.yml
|
||||
node_modules/
|
||||
|
||||
# Artifacts
|
||||
/dist/
|
||||
dist/
|
||||
|
||||
# Generated files
|
||||
.docusaurus
|
||||
|
@ -27,4 +27,7 @@ swagger generate client -P rest_model_zrok.Principal -f "$zrokSpec" -c rest_clie
|
||||
echo "...generating js client"
|
||||
openapi -s specs/zrok.yml -o ui/src/api -l js
|
||||
|
||||
echo "...generating ts client"
|
||||
openapi-generator-cli generate -i specs/zrok.yml -o sdk/node/sdk/src/zrok/api -g typescript-node
|
||||
|
||||
git checkout rest_server_zrok/configure_zrok.go
|
||||
|
38
sdk/node/examples/pastebin/dist/index.js
vendored
38
sdk/node/examples/pastebin/dist/index.js
vendored
@ -1,20 +1,42 @@
|
||||
"use strict";
|
||||
const { Command } = require("commander"); // add this line
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
const { Command } = require("commander");
|
||||
const zrok = require("zrok");
|
||||
//const environ = require("zrok/environment")
|
||||
const ziti = require('@openziti/ziti-sdk-nodejs');
|
||||
const express = require('express');
|
||||
const program = new Command();
|
||||
program
|
||||
.command('copyto')
|
||||
.version("1.0.0")
|
||||
.description("command to host content to be pastedfrom'd")
|
||||
.action(() => {
|
||||
console.log('copyto command called');
|
||||
//console.log(environ)
|
||||
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
||||
let root = zrok.Load();
|
||||
let shr = zrok.CreateShare(root, new zrok.ShareRequest(zrok.TCP_TUNNEL_BACKEND_MODE, zrok.PUBLIC_SHARE_MODE, "pastebin"));
|
||||
console.log(shr);
|
||||
//await ziti.init( root.env.ZitiIdentity ).catch(( err: Error ) => { console.error(err); return process.exit(1) });
|
||||
ziti.setLogLevel(10);
|
||||
let shr = yield zrok.CreateShare(root, new zrok.ShareRequest(zrok.TCP_TUNNEL_BACKEND_MODE, zrok.PUBLIC_SHARE_MODE, "pastebin", ["public"]));
|
||||
console.log("setting up app");
|
||||
let service = "ns5ix2brb61f";
|
||||
console.log("attempting to bind to service: " + service);
|
||||
let app = ziti.express(express, service);
|
||||
console.log("after setting up app");
|
||||
app.get('/', function (_, res) {
|
||||
res.write("Test");
|
||||
});
|
||||
console.log("after setting up get");
|
||||
//app.listen(undefined, () => {
|
||||
// console.log(`Example app listening!`)
|
||||
//})
|
||||
console.log("after listen");
|
||||
zrok.DeleteShare(root, shr);
|
||||
});
|
||||
}));
|
||||
program
|
||||
.command('pastefrom <shrToken>')
|
||||
.version("1.0.0")
|
||||
|
2
sdk/node/examples/pastebin/dist/index.js.map
vendored
2
sdk/node/examples/pastebin/dist/index.js.map
vendored
@ -1 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,MAAM,EAA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CAAA;IAC3B,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC9B,CAAC,CAAA,CAAC,CAAC;AAEL,OAAO;KACJ,OAAO,CAAC,sBAAsB,CAAC;KAC/B,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,sCAAsC,CAAC;KACnD,MAAM,CAAC,CAAC,QAAgB,EAAE,EAAE;IAC3B,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,QAAQ,CAAC,CAAC;AACpD,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;AAC3B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC"}
|
7
sdk/node/examples/pastebin/openapitools.json
Normal file
7
sdk/node/examples/pastebin/openapitools.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
|
||||
"spaces": 2,
|
||||
"generator-cli": {
|
||||
"version": "7.1.0"
|
||||
}
|
||||
}
|
2838
sdk/node/examples/pastebin/package-lock.json
generated
2838
sdk/node/examples/pastebin/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,8 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"@openziti/ziti-sdk-nodejs": "^0.14.2",
|
||||
"commander": "^11.1.0",
|
||||
"express": "^4.18.2",
|
||||
"path": "^0.12.7",
|
||||
"zrok": "../../sdk_ts/dist"
|
||||
},
|
||||
|
@ -1,6 +1,8 @@
|
||||
const { Command } = require("commander"); // add this line
|
||||
const { Command } = require("commander");
|
||||
const zrok = require("zrok")
|
||||
//const environ = require("zrok/environment")
|
||||
const ziti = require('@openziti/ziti-sdk-nodejs')
|
||||
const express = require('express')
|
||||
|
||||
|
||||
const program = new Command();
|
||||
|
||||
@ -8,12 +10,24 @@ program
|
||||
.command('copyto')
|
||||
.version("1.0.0")
|
||||
.description("command to host content to be pastedfrom'd")
|
||||
.action(() => {
|
||||
console.log('copyto command called');
|
||||
//console.log(environ)
|
||||
.action(async () => {
|
||||
let root = zrok.Load()
|
||||
let shr = zrok.CreateShare(root, new zrok.ShareRequest(zrok.TCP_TUNNEL_BACKEND_MODE, zrok.PUBLIC_SHARE_MODE, "pastebin"));
|
||||
console.log(shr)
|
||||
//await ziti.init( root.env.ZitiIdentity ).catch(( err: Error ) => { console.error(err); return process.exit(1) });
|
||||
ziti.setLogLevel(10)
|
||||
let shr = await zrok.CreateShare(root, new zrok.ShareRequest(zrok.TCP_TUNNEL_BACKEND_MODE, zrok.PUBLIC_SHARE_MODE, "pastebin", ["public"]));
|
||||
console.log("setting up app")
|
||||
let service = "ns5ix2brb61f"
|
||||
console.log("attempting to bind to service: "+ service)
|
||||
let app = ziti.express( express, service );
|
||||
console.log("after setting up app")
|
||||
app.get('/',function(_: Request,res: any){
|
||||
res.write("Test")
|
||||
});
|
||||
console.log("after setting up get")
|
||||
//app.listen(undefined, () => {
|
||||
// console.log(`Example app listening!`)
|
||||
//})
|
||||
console.log("after listen")
|
||||
zrok.DeleteShare(root, shr);
|
||||
});
|
||||
|
||||
|
@ -1,31 +0,0 @@
|
||||
import os from "os";
|
||||
import path from "node:path"
|
||||
|
||||
function rootDir() {
|
||||
home = os.homedir()
|
||||
return path.join(home, ".zrok")
|
||||
}
|
||||
|
||||
function metadataFile() {
|
||||
zrd = rootDir()
|
||||
return path.join(zrd, "metadata.json")
|
||||
}
|
||||
|
||||
function configFile() {
|
||||
zrd = rootDir()
|
||||
return path.join(zrd, "config.json")
|
||||
}
|
||||
function environmentFile() {
|
||||
zrd = rootDir()
|
||||
return path.join(zrd, "environment.json")
|
||||
}
|
||||
|
||||
function identitiesDir() {
|
||||
zrd = rootDir()
|
||||
return path.join(zrd, "identities")
|
||||
}
|
||||
|
||||
function identityFile(name) {
|
||||
idd = identitiesDir()
|
||||
return path.join(idd, name + ".json")
|
||||
}
|
@ -1,154 +0,0 @@
|
||||
import {environmntFile, configFile, metadataFile, identityFile} from "./dirs"
|
||||
import fs from "node:fs"
|
||||
import JSON from "JSON"
|
||||
import * as gateway from "../zrok/api/gateway"
|
||||
|
||||
const V = "v0.4"
|
||||
|
||||
class Metadata {
|
||||
constructor(V, RootPath) {
|
||||
this.V = V
|
||||
this.RootPath = RootPath
|
||||
}
|
||||
}
|
||||
|
||||
class Config {
|
||||
constructor(ApiEndpoint) {
|
||||
this.ApiEndpoint = ApiEndpoint
|
||||
}
|
||||
}
|
||||
|
||||
class Environment {
|
||||
constructor(Token, ZitiIdentity, ApiEndpoint) {
|
||||
this.Token = Token
|
||||
this.ZitiIdentity = ZitiIdentity
|
||||
this.ApiEndpoint = ApiEndpoint
|
||||
}
|
||||
}
|
||||
|
||||
class ApiEndpoint {
|
||||
constructor(endpoint, frm) {
|
||||
this.endpoint = endpoint
|
||||
this.frm = frm
|
||||
}
|
||||
}
|
||||
|
||||
class Root {
|
||||
constructor(meta, cfg=Config(), env=Environment()){
|
||||
this.meta = meta
|
||||
this.cfg = cfg
|
||||
this.env = env
|
||||
if (meta === undefined) {
|
||||
let root = rootDir()
|
||||
this.meta = Metadata(V, root)
|
||||
}
|
||||
}
|
||||
|
||||
HasConfig() {
|
||||
return this.cfg !== undefined && Object.keys(this.cfg).length === 0
|
||||
}
|
||||
|
||||
Client() {
|
||||
let apiEndpoint = this.ApiEndpoint()
|
||||
|
||||
function getAuthorization(security) {
|
||||
switch(security.id) {
|
||||
case 'key': return "why"
|
||||
//case 'key': return getApiKey();
|
||||
default: console.log('default');
|
||||
}
|
||||
}
|
||||
|
||||
gateway.init({
|
||||
url: apiEndpoint + '/api/v1',
|
||||
getAuthorization
|
||||
})
|
||||
}
|
||||
|
||||
ApiEndpoint() {
|
||||
let apiEndpoint = "https://api.zrok.io"
|
||||
let frm = "binary"
|
||||
|
||||
if (this.cfg.ApiEndpoint != "") {
|
||||
apiEndpoint = this.cfg.ApiEndpoint
|
||||
frm = "config"
|
||||
}
|
||||
|
||||
env = process.env.ZROK_API_ENDPOINT
|
||||
if (env != "") {
|
||||
apiEndpoint = env
|
||||
frm = "ZROK_API_ENDPOINT"
|
||||
}
|
||||
|
||||
if (this.IsEnabled()) {
|
||||
apiEndpoint = this.env.ApiEndpoint
|
||||
frm = "env"
|
||||
}
|
||||
|
||||
return ApiEndpoint(apiEndpoint.replace(/\/+$/, ""), frm)
|
||||
}
|
||||
|
||||
IsEnabled() {
|
||||
return this.env !== undefined && Object.keys(this.env).length === 0
|
||||
}
|
||||
|
||||
PublicIdentityName() {
|
||||
return "public"
|
||||
}
|
||||
|
||||
EnvironmentIdentityName() {
|
||||
return "environment"
|
||||
}
|
||||
|
||||
ZitiIdentityName(name) {
|
||||
return identityFile(name)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function Assert() {
|
||||
if (rootExists()){
|
||||
meta = loadMetadata()
|
||||
return meta.V == V
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function Load() {
|
||||
if (rootExists()) {
|
||||
return Root(loadMetadata(), loadConfig(), loadEnvironment())
|
||||
}
|
||||
return Root()
|
||||
}
|
||||
|
||||
function rootExists() {
|
||||
mf = metadataFile()
|
||||
return fs.existsSync(mf)
|
||||
}
|
||||
|
||||
function loadMetadata() {
|
||||
mf = metadataFile()
|
||||
data = fs.readFileSync(mf)
|
||||
serialized = JSON.parse(data)
|
||||
return Metadata(serialized.v)
|
||||
}
|
||||
|
||||
function loadConfig() {
|
||||
cf = configFile()
|
||||
data = fs.readFileSync(cf)
|
||||
serialized = JSON.parse(data)
|
||||
return Config(serialized.api_endpoint)
|
||||
|
||||
}
|
||||
|
||||
function isEnabled() {
|
||||
ef = environmntFile()
|
||||
return fs.existsSync(ef)
|
||||
}
|
||||
|
||||
function loadEnvironment() {
|
||||
ef = environmntFile()
|
||||
data = fs.readFileSync(ef)
|
||||
serialized = JSON.parse(data)
|
||||
return Environment(serialized.zrok_token, serialized.ziti_identity, serialized.api_endpoint)
|
||||
}
|
@ -1 +0,0 @@
|
||||
module.exports = require("./zrok/model")
|
3790
sdk/node/sdk/package-lock.json
generated
3790
sdk/node/sdk/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -2,8 +2,14 @@
|
||||
"name": "zrok",
|
||||
"version": "1.0.0",
|
||||
"description": "SDK to enable programmatic usee of the zrok sharing methods",
|
||||
"main": "index.js",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsup --external request",
|
||||
"test": "echo \\\"Error: no test specified\\\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
@ -24,17 +30,23 @@
|
||||
},
|
||||
"homepage": "https://github.com/openziti/zrok#readme",
|
||||
"dependencies": {
|
||||
"@openziti/ziti-sdk-nodejs": "^0.14.0"
|
||||
"@openziti/ziti-sdk-nodejs": "^0.14.2",
|
||||
"axios": "^1.6.2",
|
||||
"express": "^4.18.2"
|
||||
},
|
||||
"exports": {
|
||||
".": "./index.js",
|
||||
"./zrok": "./zrok",
|
||||
"./zrok/share": "./zrok/share",
|
||||
"./environment": "./environment",
|
||||
"./environment/root": "./environment/root.js",
|
||||
"./environment/dirs": "./environment/dirs"
|
||||
".": "./dist/index.js",
|
||||
"./zrok": "./dist/zrok",
|
||||
"./environment": "./dist/environment"
|
||||
},
|
||||
"imports": {
|
||||
"./environment/dirs": "./environment/dirs.js"
|
||||
"./zrok": "./zrok"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/isomorphic-fetch": "^0.0.39",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsup": "^7.2.0",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { configFile, environmentFile, identityFile, metadataFile, rootDir } from "./dirs";
|
||||
import fs from "node:fs"
|
||||
import { Configuration, MetadataApi } from "../zrok/api"
|
||||
import { Configuration, MetadataApi, HTTPHeaders } from "../zrok/api"
|
||||
|
||||
const V = "v0.4"
|
||||
|
||||
@ -59,20 +59,24 @@ export class Root {
|
||||
return this.cfg !== undefined && Object.keys(this.cfg).length === 0
|
||||
}
|
||||
|
||||
public Client(): Configuration {
|
||||
public async Client(): Promise<Configuration> {
|
||||
let apiEndpoint = this.ApiEndpoint()
|
||||
|
||||
//let headers = {
|
||||
// "X-TOKEN": this.env.Token
|
||||
//}
|
||||
|
||||
let conf = new Configuration({
|
||||
basePath: apiEndpoint.endpoint + '/api/v1',
|
||||
accessToken: this.env.Token,
|
||||
apiKey: this.env.Token,
|
||||
//headers: headers
|
||||
})
|
||||
|
||||
let mapi = new MetadataApi(conf)
|
||||
let ver: Promise<string> = mapi.version()
|
||||
|
||||
const regex : RegExp = new RegExp("^(refs/(heads|tags)/)?" + V);
|
||||
ver.then(v => {
|
||||
console.log("got version " + v)
|
||||
await ver.then(v => {
|
||||
if(!regex.test(v)) {
|
||||
throw new Error("Expected a '" + V + "' version, received: '" + v+ "'")
|
||||
}
|
||||
@ -81,7 +85,7 @@ export class Root {
|
||||
return conf
|
||||
}
|
||||
|
||||
private ApiEndpoint(): ApiEndpoint {
|
||||
public ApiEndpoint(): ApiEndpoint {
|
||||
let apiEndpoint = "https://api.zrok.io"
|
||||
let frm = "binary"
|
||||
|
51
sdk/node/sdk/src/zrok/access.ts
Normal file
51
sdk/node/sdk/src/zrok/access.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import {Root} from "../environment/root"
|
||||
import {
|
||||
Share,
|
||||
ShareApi,
|
||||
AccessRequest,
|
||||
AccessResponse,
|
||||
AuthUser,
|
||||
UnaccessRequest} from "./api"
|
||||
import * as model from "./model"
|
||||
|
||||
export async function CreateAccess(root: Root, request: model.AccessRequest): Promise<model.Access> {
|
||||
if (!root.IsEnabled()){
|
||||
throw new Error("environment is not enabled; enable with 'zrok enable' first!")
|
||||
}
|
||||
|
||||
let out: AccessRequest = {
|
||||
envZId: root.env.ZitiIdentity,
|
||||
shrToken: request.ShareToken
|
||||
}
|
||||
|
||||
let conf = await root.Client()
|
||||
let client = new ShareApi(conf)
|
||||
let shr: AccessResponse = await client.access({body: out})
|
||||
.catch(resp => {
|
||||
throw new Error("unable to create access " + resp)
|
||||
})
|
||||
|
||||
if (shr.frontendToken == undefined) {
|
||||
throw new Error("excpedted frontend token from access. Got none")
|
||||
}
|
||||
if (shr.backendMode == undefined) {
|
||||
throw new Error("excpedted backend mode from access. Got none")
|
||||
}
|
||||
|
||||
return new model.Access(shr.frontendToken, request.ShareToken, shr.backendMode)
|
||||
}
|
||||
|
||||
export async function DeleteAccess(root: Root, acc: model.Access): Promise<void> {
|
||||
let out: UnaccessRequest = {
|
||||
frontendToken: acc.Token,
|
||||
shrToken: acc.ShareToken,
|
||||
envZId: root.env.ZitiIdentity
|
||||
}
|
||||
let conf = await root.Client()
|
||||
let client = new ShareApi(conf)
|
||||
|
||||
return client.unaccess({body:out})
|
||||
.catch(resp => {
|
||||
throw new Error("error deleting access " + resp)
|
||||
})
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user