Commit db33b024 authored by tiven wang's avatar tiven wang 🤞

Initial commit

parents
node_modules
dist
deployment
\ No newline at end of file
```json
VCAP_SERVICES={"uaa": [{"binding_name": null, "credentials": {"clientid": "sb-my-cloud-sdk-demo!t15122", "clientsecret": "v53Bda2gKxFst1RO8LVsJ+La3CU=", "identityzone": "p2001285375trial", "identityzoneid": "0e78f0ec-997e-424c-9a71-f60d3b37b338", "sburl": "https://internal-xsuaa.authentication.eu10.hana.ondemand.com", "tenantid": "0e78f0ec-997e-424c-9a71-f60d3b37b338", "tenantmode": "dedicated", "uaadomain": "authentication.eu10.hana.ondemand.com", "url": "https://p2001285375trial.authentication.eu10.hana.ondemand.com", "verificationkey": "-----BEGIN PUBLIC KEY-----MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwThn6OO9kj0bchkOGkqYBnV1dQ3zU/xtj7Kj7nDd8nyRMcEWCtVzrzjzhiisRhlrzlRIEY82wRAZNGKMnw7cvCwNixcfcDJnjzgr2pJ+5/yDZUc0IXXyIWPZD+XdL+0EogC3d4+fqyvg/BF/F0t2hKHWr/UTXE6zrGhBKaL0d8rKfYd6olGWigFd+3+24CKI14zWVxUBtC+P9Fhngc9DRzkXqhxOK/EKn0HzSgotf5duq6Tmk9DCNM4sLW4+ERc6xzrgbeEexakabvax/Az9WZ4qhwgw+fwIhKIC7WLwCEJaRsW4m7NKkv+eJR2LKYesuQ9SVAJ3EXV86RwdnH4uAv7lQHsKURPVAQBlranSqyQu0EXs2N9OlWTxe+FyNkIvyZvoLrZl/CdlYc8AKxRm5rn2/88nkrYQ0XZSrnICM5FRWgVF2hn5KfZGwtBN85/D4Yck6B3ocMfyX7e4URUm9lRPQFUJGTXaZnEIge0R159HUwhTN1HvyXrs6uT1ZZmW+c3p47dw1+LmUf/hIf8zd+uvHQjIeHEJqxjqfyA8yqAFKRHKVFrwnwdMHIsRap2EKBhHMfeVf0P2th5C9MggYoGCvdIaIUgMBX3TtCdvGrcWML7hnyS2zkrlA8SoKJnRcRF2KxWKs355FhpHpzqyZflO5l98+O8wOsFjGpL9d0ECAwEAAQ==-----END PUBLIC KEY-----", "xsappname": "my-cloud-sdk-demo!t15122"}, "instance_name": "my-xsuaa", "label": "xsuaa", "name": "my-xsuaa", "plan": "application", "provider": null, "syslog_drain_url": null, "tags": ["xsuaa"], "volume_mounts": []}]}
```
\ No newline at end of file
destinations=[{"name": "Sandbox", "url": "https://sandbox.api.sap.com/s4hanacloud/", "properties":[{"key":"ApiKey", "value":"9OLeNbRsXlZ3U2faS6bD1TnsBCYaU6gn"}]},{"name": "my300033", "url": "https://my300033-api.saps4hanacloud.cn/", "username": "Z_HG_TEST", "password": "Aa12345678901234567890!"}]
node_modules
<html>
<head>
<title>Welcome to Your Application!</title>
<style>
body {
font-family: Arial, sans-serif;
color: #333333;
}
a {
color: #0c7ecf;
}
li {
margin: 10px 0;
}
code {
font-family: Courier, monospace;
font-size: 95%;
padding: 0.2em;
padding-left: 0.4em;
padding-right: 0.4em;
background-color: #ebebeb;
border-radius: 3px;
}
</style>
</head>
<body>
<h1>Welcome to Your Application!</h1>
<a href="https://www.sap.com/s4sdk" class="svg">
<object
data="https://blogs.sap.com/wp-content/uploads/2019/03/190320_SDK-Logo-Javascript_final_freeform_black_no-beta_small.png"
type="image/png"
width="150px"
></object>
</a>
<p>
This is your
<strong>SAP Cloud Platform Cloud Foundry express.js</strong> application
powered by the
<strong>SAP Cloud SDK for TypeScript / JavaScript</strong>.
</p>
<ul>
<li>
Execute <code>npm run start:local</code> to run the server or
<code>npm run watch:local</code> to run it in debug mode.
</li>
<li>
Visit the <a href="hello">hello-world-route</a>. You can find its source
code in <code>src/hello-world-route.ts</code>.
</li>
</ul>
<p>
Further help and examples are available
<a href="https://help.sap.com/viewer/product/SAP_S4HANA_CLOUD_SDK/1.0">here</a>.
</p>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
{
"name": "my-cloud-sdk-demo",
"version": "1.0.0",
"description": "SAP Cloud SDK Demo",
"main": "index.js",
"scripts": {
"init": "npm i && node initialize.js",
"test": "echo \"Error: no test specified\" && exit 1",
"start:local": "npx ts-node -r dotenv/config src/",
"watch:local": "nodemon -e ts -w ./src -x npm run serve-debug",
"serve-debug": "node -r ts-node/register --inspect src/index.ts",
"ci-build": "npx tsc",
"ci-package": "npm prune --production && cp -r node_modules dist package.json index.html deployment/",
"ci-backend-unit-test": "nyc --extension .ts --report-dir ./s4hana_pipeline/reports/coverage-reports/backend-unit/ --reporter cobertura mocha -r ts-node/register test/unit-tests/*.spec.ts --reporter mocha-junit-reporter --reporter-options mochaFile=./s4hana_pipeline/reports/backend-unit/results.xml",
"ci-integration-test": "nyc --extension .ts --report-dir ./s4hana_pipeline/reports/coverage-reports/backend-integration/ --reporter cobertura mocha -r ts-node/register test/integration-tests/*.spec.ts --reporter mocha-junit-reporter --reporter-options mochaFile=./s4hana_pipeline/reports/backend-integration/results.xml"
},
"keywords": [
"SAP",
"Cloud",
"SDK",
"S4HANA",
"Cloud"
],
"author": "tiven.wang",
"license": "ISC",
"dependencies": {
"@sap/cloud-sdk-vdm-accounting-document-service": "^1.2.1",
"@sap/cloud-sdk-vdm-business-partner-service": "^1.2.1",
"@sap/cloud-sdk-vdm-trial-balance-service": "^1.2.1",
"@sap/xsenv": "^2.0.0",
"@sap/xssec": "^2.1.17",
"@types/express": "^4.16.1",
"cfenv": "^1.2.2",
"passport": "^0.4.0",
"ts-node": "^8.1.0",
"typescript": "^3.4.5"
},
"devDependencies": {
"dotenv": "^8.0.0",
"express": "^4.17.0"
},
"engines": {
"node": "10.15.x"
}
}
import { Request, Response } from 'express';
import { OperationalAcctgDocItemCube } from '@sap/cloud-sdk-vdm-accounting-document-service';
import { or, and } from '@sap/cloud-sdk-core';
function getAllOperationalAcctgDocItemCube(): Promise<OperationalAcctgDocItemCube[]> {
return OperationalAcctgDocItemCube.requestBuilder()
.getAll()
.select(
OperationalAcctgDocItemCube.ACCOUNTING_DOCUMENT_CATEGORY_NAME,
)
// .filter(or(
// and(
// BusinessPartner.FIRST_NAME.equals('Jason'),
// BusinessPartner.LAST_NAME.equals('Hoskins'),
// )
// ))
.top(10)
// .skip(0)
// .withCustomHeaders({
// 'APIKey': '9OLeNbRsXlZ3U2faS6bD1TnsBCYaU6gn'
// })
.execute({
destinationName: 'my300033'
});
}
export async function operationalAcctgDocItemCube(req: Request, res: Response) {
res.status(200).send(await getAllOperationalAcctgDocItemCube());
}
\ No newline at end of file
import express from "express";
import { helloWorld } from "./hello-world-route";
import { indexRoute } from "./index-route";
import { businessPartners } from './business-partner-route';
import { operationalAcctgDocItemCube } from './accounting-document-route';
const passport = require('passport');
const xsenv = require('@sap/xsenv');
const JWTStrategy = require('@sap/xssec').JWTStrategy;
const cfenv = require("cfenv");
const appEnv = cfenv.getAppEnv();
class App {
public app: express.Application;
constructor() {
this.app = express();
this.config();
this.routes();
}
private config(): void {
this.app.use(express.json());
this.app.use(express.urlencoded({ extended: false }));
// if(appEnv.port) {
// const services = xsenv.getServices({ uaa:'my-xsuaa' });
// passport.use(new JWTStrategy(services.uaa));
// this.app.use(passport.initialize());
// this.app.use(passport.authenticate('JWT', { session: false }));
// }
}
private routes(): void {
const router = express.Router();
router.get("/", indexRoute);
router.get("/hello", helloWorld);
router.get('/business-partners', businessPartners);
router.get('/accounting', operationalAcctgDocItemCube);
this.app.use("/", router);
}
}
export default new App().app;
\ No newline at end of file
import { Request, Response } from 'express';
import { BusinessPartner, Customer } from '@sap/cloud-sdk-vdm-business-partner-service';
import { or, and } from '@sap/cloud-sdk-core';
function getAllBusinessPartners(): Promise<BusinessPartner[]> {
return BusinessPartner.requestBuilder()
.getAll()
.select(
BusinessPartner.FIRST_NAME,
BusinessPartner.LAST_NAME,
BusinessPartner.BUSINESS_PARTNER_FULL_NAME,
BusinessPartner.TO_CUSTOMER.select(
Customer.CUSTOMER
)
)
// .filter(or(
// and(
// BusinessPartner.FIRST_NAME.equals('Jason'),
// BusinessPartner.LAST_NAME.equals('Hoskins'),
// )
// ))
.top(10)
// .skip(0)
// .withCustomHeaders({
// 'APIKey': '9OLeNbRsXlZ3U2faS6bD1TnsBCYaU6gn'
// })
.execute({
destinationName: 'my300033'
});
}
export async function businessPartners(req: Request, res: Response) {
// getAllBusinessPartners().then((bps)=> {
// console.log(bps);
// res.status(200).send(bps);
// });
res.status(200).send(await getAllBusinessPartners());
}
\ No newline at end of file
import { Request, Response } from "express";
export function helloWorld(req: Request, res: Response) {
res.status(200).send("Hello, World!");
}
\ No newline at end of file
import { Request, Response } from "express";
import { resolve } from "path";
export function indexRoute(req: Request, res: Response) {
res.sendFile(resolve(__dirname, "../index.html"));
}
\ No newline at end of file
import app from "./application";
const cfenv = require("cfenv");
const appEnv = cfenv.getAppEnv();
const port = 8080;
app.listen(appEnv.port || port, appEnv.bind, () => {
console.log("Express server listening on port " + appEnv.url);
});
export default app;
\ No newline at end of file
{
"compilerOptions": {
/* Basic Options */
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "dist" /* Redirect output structure to the directory. */,
"rootDir": "src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"exclude": [
"test"
]
}
\ No newline at end of file
Getting key local_test for service instance my-xsuaa as [email protected]
{
"clientid": "sb-my-cloud-sdk-demo!t15122",
"clientsecret": "v53Bda2gKxFst1RO8LVsJ+La3CU=",
"identityzone": "p2001285375trial",
"identityzoneid": "0e78f0ec-997e-424c-9a71-f60d3b37b338",
"sburl": "https://internal-xsuaa.authentication.eu10.hana.ondemand.com",
"tenantid": "0e78f0ec-997e-424c-9a71-f60d3b37b338",
"tenantmode": "dedicated",
"uaadomain": "authentication.eu10.hana.ondemand.com",
"url": "https://p2001285375trial.authentication.eu10.hana.ondemand.com",
"verificationkey": "-----BEGIN PUBLIC KEY-----MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwThn6OO9kj0bchkOGkqYBnV1dQ3zU/xtj7Kj7nDd8nyRMcEWCtVzrzjzhiisRhlrzlRIEY82wRAZNGKMnw7cvCwNixcfcDJnjzgr2pJ+5/yDZUc0IXXyIWPZD+XdL+0EogC3d4+fqyvg/BF/F0t2hKHWr/UTXE6zrGhBKaL0d8rKfYd6olGWigFd+3+24CKI14zWVxUBtC+P9Fhngc9DRzkXqhxOK/EKn0HzSgotf5duq6Tmk9DCNM4sLW4+ERc6xzrgbeEexakabvax/Az9WZ4qhwgw+fwIhKIC7WLwCEJaRsW4m7NKkv+eJR2LKYesuQ9SVAJ3EXV86RwdnH4uAv7lQHsKURPVAQBlranSqyQu0EXs2N9OlWTxe+FyNkIvyZvoLrZl/CdlYc8AKxRm5rn2/88nkrYQ0XZSrnICM5FRWgVF2hn5KfZGwtBN85/D4Yck6B3ocMfyX7e4URUm9lRPQFUJGTXaZnEIge0R159HUwhTN1HvyXrs6uT1ZZmW+c3p47dw1+LmUf/hIf8zd+uvHQjIeHEJqxjqfyA8yqAFKRHKVFrwnwdMHIsRap2EKBhHMfeVf0P2th5C9MggYoGCvdIaIUgMBX3TtCdvGrcWML7hnyS2zkrlA8SoKJnRcRF2KxWKs355FhpHpzqyZflO5l98+O8wOsFjGpL9d0ECAwEAAQ==-----END PUBLIC KEY-----",
"xsappname": "my-cloud-sdk-demo!t15122"
}
const fs = require("fs");
const yaml = require("js-yaml");
if (process.argv.length !== 3) {
console.error(
"You have not provided a name to set. Usage: npm run init -- <YOUR-APPNAME>"
);
process.exit(1);
}
const name = process.argv.splice(-1)[0];
console.log(`Using ${name} as name...`);
console.log("Setting appname in package.json...");
const packageJson = JSON.parse(fs.readFileSync("./package.json", "utf8"));
packageJson.name = name;
fs.writeFileSync("./package.json", JSON.stringify(packageJson, null, 2) + "\n");
console.log("Setting appname in manifest.yml...");
const manifestYml = yaml.load(fs.readFileSync("./manifest.yml", "utf8"));
manifestYml.applications[0].name = name;
fs.writeFileSync("./manifest.yml", yaml.dump(manifestYml));
console.log("Done!");
\ No newline at end of file
applications:
- name: my-cloud-sdk-demo
path: app/deployment/
buildpacks:
- nodejs_buildpack
memory: 256M
command: node dist/index.js
random-route: true
services:
- my-destination
- my-xsuaa
- name: web
path: web
buildpacks:
- nodejs_buildpack
memory: 128M
command: npm run start
random-route: true
env:
destinations: >
[
{
"name":"myapp",
"url":"https://my-cloud-sdk-demo-balanced-baboon.cfapps.eu10.hana.ondemand.com/",
"forwardAuthToken": true
}
]
services:
- my-xsuaa
\ No newline at end of file
This diff is collapsed.
{
"name": "web",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node node_modules/@sap/approuter/approuter.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@sap/approuter": "^6.0.0"
},
"engines": {
"node": "10.15.x"
}
}
<html>
<head>
<title>JavaScript Tutorial</title>
</head>
<body>
<h1>JavaScript Tutorial</h1>
<a href="/business-partners/">myapp</a>
</body>
</html>
\ No newline at end of file
{
"routes": [
{
"source": "^/business-partners/(.*)$",
"target": "$1",
"destination": "myapp"
}
]
}
\ No newline at end of file
{
"xsappname": "my-cloud-sdk-demo",
"tenant-mode": "dedicated"
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment