├── .babelrc ├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── .ipynb_checkpoints ├── Untitled-checkpoint.ipynb └── Untitled1-checkpoint.ipynb ├── .npmrc ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── SUPPORT.md ├── babelrctemplate ├── cas.json ├── changelog.md ├── data ├── Cluster_SDOH1.sas ├── Cluster_SDOH6.sas ├── GRADIENT_BOOSTING___BAD_2.sashdat ├── LeNet_snzrle.astore ├── NeuralNetwork_High_med.sas ├── NeuralNetwork_high_med1.sas ├── ast │ ├── GBlocalcopy.sasast │ ├── LeNet_snzrle.astore │ ├── gb_IrisGB.sasast │ ├── paysimsvdd.sasast │ └── svmlocalcopy.sasast ├── cars.csv ├── cluster_test2.sas7bdat ├── cmdList.txt ├── cms_opioid_sdoh.sas7bdat ├── columns.json ├── iris.csv └── testdata.csv ├── doc.html ├── doc.md ├── images ├── CommonScenarios.png ├── caslScore.png ├── caslrun.png ├── masREST.png └── quickstart.png ├── jsdoc.json ├── main-types.js ├── package copy.json ├── package-lock.json ├── package.json ├── packages ├── examples │ ├── .dockerignore │ ├── README.md │ ├── basics.test.js │ ├── cas.actions.test.js │ ├── cas.score.test.js │ ├── cas.sessions.test.js │ ├── cas.upload.test.js │ ├── compute.test.js │ ├── core.test.js │ ├── data │ │ ├── Cluster_SDOH1.sas │ │ ├── GBlocalcopy.sasast │ │ ├── GRADIENT_BOOSTING___BAD_2.sashdat │ │ ├── LeNet_snzrle.astore │ │ ├── cars.csv │ │ ├── cluster_test2.sas7bdat │ │ ├── paysimsvdd.sasast │ │ ├── test2.sas │ │ └── testdata.csv │ ├── decisions.test.js │ ├── files.test.js │ ├── folders.test.js │ ├── lib │ │ ├── configtest.js │ │ ├── getToken.js │ │ ├── listCaslibs.js │ │ ├── setupAll.js │ │ └── testLogger.js │ ├── notes │ │ ├── authentication.md │ │ ├── caslScore.html │ │ ├── caslScore.png │ │ └── caslrun.html │ ├── package.json │ ├── programs │ │ └── scoreCasl.js │ ├── puptests │ │ ├── basic.js │ │ └── easy.js │ ├── scripts │ │ └── start.sh │ ├── start.sh │ └── testFunctions │ │ ├── addServices.js │ │ ├── addServices2.js │ │ ├── appData.js │ │ ├── casAppendTable1.js │ │ ├── casDSLoad.js │ │ ├── casDSandFetch.js │ │ ├── casDSandFetch2.js │ │ ├── casDSandFetch2v2.js │ │ ├── casEcho.js │ │ ├── casFetchData3.js │ │ ├── casFetchScroll.js │ │ ├── casFetchScrollFail.js │ │ ├── casFetchScrollWhere.js │ │ ├── casScoreAst.js │ │ ├── casScoreAstFail.js │ │ ├── casScoreHdat.js │ │ ├── casSession.js │ │ ├── casSessionAttach.js │ │ ├── casSubmit.js │ │ ├── casTables.js │ │ ├── casUnique.js │ │ ├── casUploadAst.js │ │ ├── casUploadCsv.js │ │ ├── casUploadCsv2.js │ │ ├── casUploadCsv3.js │ │ ├── casUploadProgram.js │ │ ├── casUploadProgram2.js │ │ ├── casUploadbdat.js │ │ ├── casUploadhdat.js │ │ ├── casUploadnew.js │ │ ├── computeBasic.js │ │ ├── computeDSAttach.js │ │ ├── computeFetchScroll.js │ │ ├── computeFetchScrollWhere.js │ │ ├── computeTables.js │ │ ├── computeWithPreamble.js │ │ ├── filesCreate.js │ │ ├── filesPaginate.js │ │ ├── foldersPaginate.js │ │ ├── identities.js │ │ ├── index.js │ │ ├── logonTest.js │ │ ├── masList.js │ │ ├── masScore.js │ │ ├── mlPipeline.js │ │ ├── mlPipelinePublish.js │ │ ├── modelDestinationCas.js │ │ ├── modelRepoRoot.js │ │ └── parentURI.js ├── restaf │ ├── .babelrc │ ├── README.md │ ├── dist │ │ ├── restaf.js │ │ └── restaf.min.js │ ├── jsdoc.json │ ├── lib │ │ └── restaf.js │ ├── package.json │ ├── src │ │ ├── actionTypes │ │ │ └── index.js │ │ ├── index.js │ │ ├── reducers │ │ │ ├── baseReducer.js │ │ │ ├── createReducer.js │ │ │ ├── injectAsyncReducers.js │ │ │ ├── responseReducer.js │ │ │ └── viyaLogon.js │ │ ├── sagas │ │ │ ├── apiCall.js │ │ │ ├── apiCallAction.js │ │ │ ├── apiCallAllAction.js │ │ │ ├── apiPoll.js │ │ │ ├── apiPollAction.js │ │ │ ├── appDataAction.js │ │ │ ├── httpCall.js │ │ │ ├── httpCallWait.js │ │ │ ├── keepAliveAction.js │ │ │ ├── logonAction.js │ │ │ ├── rafObjectAction.js │ │ │ └── rootSaga.js │ │ ├── serverCalls │ │ │ ├── casSessionLinks.js │ │ │ ├── fixImages.js │ │ │ ├── fixMlPipelineAutomation.js │ │ │ ├── fixReports.js │ │ │ ├── fixResponse.js │ │ │ ├── index.js │ │ │ └── reduceCasResults.js │ │ ├── store │ │ │ ├── addServices.js │ │ │ ├── apiCall.js │ │ │ ├── apiCallAll.js │ │ │ ├── apiSubmit.js │ │ │ ├── appData.js │ │ │ ├── configureSagaStore.js │ │ │ ├── deleteRafObject.js │ │ │ ├── endStore.js │ │ │ ├── extendFolder.js │ │ │ ├── getResults.js │ │ │ ├── getResults2.js │ │ │ ├── getServiceRoot.js │ │ │ ├── getServices.js │ │ │ ├── getXsrfData.js │ │ │ ├── iGetResults.js │ │ │ ├── iaddServices.js │ │ │ ├── iapiCall.js │ │ │ ├── ijobState.js │ │ │ ├── ijobStateAll.js │ │ │ ├── ikeepAlive.js │ │ │ ├── index.js │ │ │ ├── initStore.js │ │ │ ├── jobState.js │ │ │ ├── jobStateAll.js │ │ │ ├── keepViyaAlive.js │ │ │ ├── logoff.js │ │ │ ├── logon.js │ │ │ ├── prepareAction.js │ │ │ ├── readXsrfData.js │ │ │ ├── request.js │ │ │ ├── restoreStore.js │ │ │ ├── routeToObj.js │ │ │ ├── runAction.js │ │ │ ├── selectLogonInfo.js │ │ │ └── xsrfData.js │ │ └── utils │ │ │ ├── SASLogoffOauthLink.js │ │ │ ├── SASLogonOauthLink.js │ │ │ ├── index.js │ │ │ ├── rootStruct.js │ │ │ ├── routeOrFolder.js │ │ │ └── statusFuncs.js │ ├── webpack.config.es.js │ └── webpack.config.js ├── restaflib │ ├── .babelrc │ ├── README.md │ ├── dist │ │ ├── restaflib.js │ │ └── restaflib.min.js │ ├── jsdoc.json │ ├── lib │ │ └── restaflib.js │ ├── package.json │ ├── src │ │ ├── casActionRun.js │ │ ├── casAppendTable.js │ │ ├── casFetchData.js │ │ ├── casFetchRows.js │ │ ├── casLoadTable.js │ │ ├── casSaveTable.js │ │ ├── casSetup.js │ │ ├── casTableSummary.js │ │ ├── casTableToJson.js │ │ ├── casUpdateData.js │ │ ├── casUpload.txt │ │ ├── caslDescribe.js │ │ ├── caslRun.js │ │ ├── caslRunBase.js │ │ ├── caslScore.js │ │ ├── computeAppendTable.js │ │ ├── computeFetchData.js │ │ ├── computeFileContent.js │ │ ├── computeResults.js │ │ ├── computeRun.js │ │ ├── computeRunBase.js │ │ ├── computeSetup.js │ │ ├── computeSetupTables.js │ │ ├── computeSummary.js │ │ ├── computeUpdateData.js │ │ ├── computeUpload.js │ │ ├── findReport.js │ │ ├── getReportImage.js │ │ ├── getReportUri.js │ │ ├── getSasTableRows.js │ │ ├── getScoreStep.js │ │ ├── index.js │ │ ├── jesRun.js │ │ ├── jesRunBase.js │ │ ├── jesSetup.js │ │ ├── jesSummary.js │ │ ├── jsonToDict.js │ │ ├── lib.js │ │ ├── masAddModel.js │ │ ├── masDescribe.js │ │ ├── masRun.js │ │ ├── masScore.js │ │ ├── masSetup.js │ │ ├── print │ │ │ └── logListLines.js │ │ ├── programs │ │ │ ├── casAppendTable.js │ │ │ ├── casFetchData.js │ │ │ ├── casFetchRows.js │ │ │ ├── commonCasl.js │ │ │ ├── index.js │ │ │ └── scoreCasl.js │ │ ├── uploadData.txt │ │ ├── uploadHandlers │ │ │ ├── index.js │ │ │ ├── saveTable.js │ │ │ ├── uploadAstore.js │ │ │ └── uploadSrc.js │ │ └── uploadSetup.js │ ├── webpack.config.es.js │ └── webpack.config.js └── tests │ ├── appData.js │ ├── cas.append.table.test.js │ ├── cas.basic.test.js │ ├── cas.ds.load.test.js │ ├── cas.fetch.scroll.fail.test.js │ ├── cas.fetch.scroll.test.js │ ├── cas.fetch.scroll.where.test.js │ ├── cas.session.test.js │ ├── cas.submit.test.js │ ├── cas.unique.test.js │ ├── compute.attach.test.js │ ├── compute.basic.test.js │ ├── compute.fetch.scroll.test.js │ ├── compute.fetch.scroll.where.test.js │ ├── compute.reuse.test.js │ ├── compute.unique.test.js │ ├── computeTable.test.js │ ├── filesCreate.test.js │ ├── filesPaginate.test.js │ ├── foldersPaginate.test.js │ ├── maslist.test.js │ ├── masscore.test.js │ ├── masscore2.test.js │ ├── package.json │ ├── parentURI.test.js │ └── restaf.basic.test.js └── quicktest.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env" 4 | ], 5 | "plugins": [ 6 | "@babel/plugin-transform-regenerator", 7 | "@babel/plugin-transform-runtime", 8 | "@babel/plugin-syntax-dynamic-import", 9 | "@babel/plugin-syntax-import-meta", 10 | "@babel/plugin-proposal-class-properties", 11 | "@babel/plugin-proposal-json-strings", 12 | [ 13 | "@babel/plugin-proposal-decorators", 14 | { 15 | "legacy": true 16 | } 17 | ], 18 | "@babel/plugin-proposal-function-sent", 19 | "@babel/plugin-proposal-export-namespace-from", 20 | "@babel/plugin-proposal-numeric-separator", 21 | "@babel/plugin-proposal-throw-expressions", 22 | "@babel/plugin-proposal-export-default-from", 23 | "@babel/plugin-proposal-logical-assignment-operators", 24 | "@babel/plugin-proposal-optional-chaining", 25 | [ 26 | "@babel/plugin-proposal-pipeline-operator", 27 | { 28 | "proposal": "minimal" 29 | } 30 | ], 31 | "@babel/plugin-proposal-nullish-coalescing-operator", 32 | "@babel/plugin-proposal-do-expressions", 33 | "@babel/plugin-proposal-function-bind", 34 | "@babel/plugin-proposal-object-rest-spread" 35 | ] 36 | } -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | public 3 | dist 4 | lib 5 | data 6 | images 7 | packages/examples 8 | packages/tests -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "env": { 4 | "browser": true, 5 | "node": true, 6 | "es6": true 7 | }, 8 | "parser": "babel-eslint", 9 | "extends": [ 10 | "eslint:recommended" 11 | ], 12 | "parserOptions": { 13 | "ecmaVersion": 2020, 14 | "ecmaFeatures": { 15 | "legacyDecorators": true, 16 | "jsx": true 17 | } 18 | }, 19 | "rules": { 20 | "key-spacing": [ 21 | 2, 22 | { 23 | "align": "colon" 24 | } 25 | ], 26 | "jsx-quotes": [ 27 | 2, 28 | "prefer-double" 29 | ], 30 | "no-console": 0, 31 | "no-unused-vars": [ 32 | 0, 33 | { 34 | "args": "none" 35 | } 36 | ], 37 | "no-debugger": 0, 38 | "react/prop-types": 0, 39 | "array-bracket-spacing": [ 40 | 2, 41 | "always" 42 | ], 43 | "space-in-parens": [0,"never"], 44 | 45 | "no-prototype-builtins": "off" 46 | 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .idea 3 | pems 4 | debug.log 5 | 6 | 7 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/Untitled-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 5 6 | } 7 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/Untitled1-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 5 6 | } 7 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | npm config set registry https://registry.npmjs.org/ -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.fontSize": 10, 3 | "SAS.session.clientId": "sas.ec", 4 | "SAS.session.user": "sastest1", 5 | "SAS.session.host": "https://viya.kdk-fsedit-azure-nginx-21a2b90b.unx.sas.com" 6 | } -------------------------------------------------------------------------------- /SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Support 2 | 3 | We use GitHub for tracking bugs and feature requests. Please submit a GitHub issue or pull request for support. 4 | -------------------------------------------------------------------------------- /babelrctemplate: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ "@babel/preset-env" ], 3 | "plugins": [ 4 | "@babel/plugin-transform-regenerator", 5 | "@babel/plugin-transform-runtime", 6 | "@babel/plugin-syntax-dynamic-import", 7 | "@babel/plugin-syntax-import-meta", 8 | "@babel/plugin-proposal-class-properties", 9 | "@babel/plugin-proposal-json-strings", 10 | [ 11 | "@babel/plugin-proposal-decorators", 12 | { 13 | "legacy": true 14 | } 15 | ], 16 | "@babel/plugin-proposal-function-sent", 17 | "@babel/plugin-proposal-export-namespace-from", 18 | "@babel/plugin-proposal-numeric-separator", 19 | "@babel/plugin-proposal-throw-expressions", 20 | "@babel/plugin-proposal-export-default-from", 21 | "@babel/plugin-proposal-logical-assignment-operators", 22 | "@babel/plugin-proposal-optional-chaining", 23 | [ 24 | "@babel/plugin-proposal-pipeline-operator", 25 | { 26 | "proposal": "minimal" 27 | } 28 | ], 29 | "@babel/plugin-proposal-nullish-coalescing-operator", 30 | "@babel/plugin-proposal-do-expressions", 31 | "@babel/plugin-proposal-function-bind", 32 | "@babel/plugin-proposal-object-rest-spread", 33 | "@babel/plugin-transform-spread", 34 | "@babel/plugin-transform-strict-mode" 35 | ] 36 | } -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Changes 2 | 3 | ## 5.0.0 4 | 5 | Next gen 6 | 7 | ## 5.0.2 8 | 9 | - New store options 10 | - proxyServer - redirect calls to proxyserver 11 | - computeServerId - id of work bench compute server 12 | 13 | ## 5.0.3 14 | 15 | - compute/session filter seems to be broken. So doing local filtering until the issue is resolved. 16 | 17 | ## 5.0.4 18 | 19 | - make companion changes to 5.0.3 changes 20 | 21 | ## 5.0.5 22 | 23 | - undo previous two patches 24 | 25 | ## 5.0.10-test 26 | 27 | - fixed issues with restaflib/src/programs 28 | - cleaned up dependencies 29 | 30 | -------------------------------------------------------------------------------- /data/GRADIENT_BOOSTING___BAD_2.sashdat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/data/GRADIENT_BOOSTING___BAD_2.sashdat -------------------------------------------------------------------------------- /data/LeNet_snzrle.astore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/data/LeNet_snzrle.astore -------------------------------------------------------------------------------- /data/ast/GBlocalcopy.sasast: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/data/ast/GBlocalcopy.sasast -------------------------------------------------------------------------------- /data/ast/LeNet_snzrle.astore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/data/ast/LeNet_snzrle.astore -------------------------------------------------------------------------------- /data/ast/gb_IrisGB.sasast: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/data/ast/gb_IrisGB.sasast -------------------------------------------------------------------------------- /data/ast/paysimsvdd.sasast: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/data/ast/paysimsvdd.sasast -------------------------------------------------------------------------------- /data/ast/svmlocalcopy.sasast: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/data/ast/svmlocalcopy.sasast -------------------------------------------------------------------------------- /data/cluster_test2.sas7bdat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/data/cluster_test2.sas7bdat -------------------------------------------------------------------------------- /data/cmdList.txt: -------------------------------------------------------------------------------- 1 | upload --file ../../data/Cluster_SDOH1.sas --output public.MODEL_CLUSTER_SDOH1 2 | upload --file ../../data/Cluster_SDOH6.sas --output public.MODEL_CLUSTER_SDOH6 3 | upload --file ../../data/NeuralNetwork_High_med.sas --output public.MODEL_NEURALNETWORK_HIGH_MED 4 | upload --file ../../data/NeuralNetwork_high_med1.sas --output public.NeuralNetwork_high_med1 5 | 6 | upload --file ../../data/LeNet_snzrle.astore --output models.Lenet_snzrle 7 | 8 | upload --file ../../data/cars.csv --output public.cars 9 | upload --file ../../data/cars.csv --output public.cars 10 | upload --file ../../data/cms_opioid_sdoh.sas7bdat --output public.cms_opioid_sdoh 11 | upload --file ../../data/cluster_test2.sas7bdat --output public.cluster_test2 12 | upload --file ../../data/GRADIENT_BOOSTING___BAD_2.sashdat --output public.GRADIENT_BOOSTING___BAD_2 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /data/cms_opioid_sdoh.sas7bdat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/data/cms_opioid_sdoh.sas7bdat -------------------------------------------------------------------------------- /data/columns.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/data/columns.json -------------------------------------------------------------------------------- /data/testdata.csv: -------------------------------------------------------------------------------- 1 | id,x1,x2,x3 2 | k1,1,2,3 3 | k2,2,3,4 4 | k3,5,6,7 5 | k4,6,7,30 6 | k5,7,3,4 7 | k6,8,9,0 8 | k7,1,2,3 9 | k8,2,3,4 10 | k9,5,6,7 11 | k11,1,2,3 12 | K21,2,3,4 13 | k31,5,6,7 14 | k41,6,7,30 15 | k51,7,3,4 16 | k61,8,9,0 17 | k71,1,2,3 18 | k81,2,3,4 19 | k91,5,6,7 20 | -------------------------------------------------------------------------------- /images/CommonScenarios.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/images/CommonScenarios.png -------------------------------------------------------------------------------- /images/caslScore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/images/caslScore.png -------------------------------------------------------------------------------- /images/caslrun.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/images/caslrun.png -------------------------------------------------------------------------------- /images/masREST.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/images/masREST.png -------------------------------------------------------------------------------- /images/quickstart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/images/quickstart.png -------------------------------------------------------------------------------- /jsdoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["plugins/markdown", "node_modules/better-docs/category"], 3 | "recurseDepth": 10, 4 | "source": { 5 | "include": [ 6 | "main-types.js", 7 | ".other packages..." 8 | ], 9 | "exclude": ["./packages/restaflib/src/print"], 10 | "includePattern": ".js", 11 | "excludePattern": "(node_modules)" 12 | }, 13 | "tags": { 14 | "allowUnknownTags": ["category"], 15 | "dictionaries": ["jsdoc"] 16 | }, 17 | 18 | "templates": { 19 | "cleverLinks": true, 20 | "search": true, 21 | "monospaceLinks": true, 22 | "useLongnameInNav": true, 23 | "showInheritedInNav": true, 24 | "default": { 25 | "outputSourceFiles": false 26 | } 27 | 28 | }, 29 | "opts": { 30 | "template": "node_modules/better-docs", 31 | "destination": "./jsdocs", 32 | "recurse": true, 33 | "private": true, 34 | "readme": "./README.md", 35 | "tutorials": "./tutorials" 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /packages/examples/.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | .cache -------------------------------------------------------------------------------- /packages/examples/README.md: -------------------------------------------------------------------------------- 1 | # Test streams 2 | 3 | All the test code is in testFunctions directory 4 | 5 | 1. **basics.test.js** -- Obtains the root links for the services listed below 6 | 7 | ```json 8 | [ 9 | "reports", 10 | "reportImages", 11 | "reportTransforms", 12 | "compute", 13 | "files", 14 | "casManagement", 15 | "modelPublish", 16 | "modelRepository", 17 | "jobExecution" 18 | ] 19 | ``` 20 | 21 | 2. **files.test.js** -- tests basic POST and GET of content 22 | 23 | - scroll and list all the files in the system 24 | 25 | - create a new file and then retrieve its content 26 | 27 | 3. **compute.test.js** - test the basic functionality of compute service 28 | 29 | - run a datastep, retrieve log and ods output, retrieve the records from the table. 30 | 31 | 4. **cas.actions.test.js** - test a few common cas actions 32 | 33 | - create a sas session 34 | - run echo action 35 | - run datastep.runcode action and fetch the resulting table 36 | - run fileInfo action 37 | - list tables in Public caslib 38 | 39 | 5. **cas.score.test.js** - upload an astore using astore action 40 | - upload a sasast and score a simple scenario 41 | - upload a model(sashdat format) and score a simple scenario 42 | 43 | 6. **cas.upload.test.js** - upload csv, bdat,hdat, sas, ds2 44 | 45 | - uploads a csv 46 | - uploads a sasb7dat 47 | - uploads a sashdat 48 | - uploads a sas program into a model sashdat 49 | - uploads a ds2 program into a model sashdat 50 | -------------------------------------------------------------------------------- /packages/examples/basics.test.js: -------------------------------------------------------------------------------- 1 | let testFunctions = require( './testFunctions' ); 2 | let testInfo; 3 | let setupAll = require( './lib/setupAll' ); 4 | 5 | beforeAll( async () => { 6 | try { 7 | 8 | console.log( 'calling setup' ); 9 | testInfo = await setupAll(); 10 | } catch ( err ) { 11 | console.log( err ); 12 | process.exit( 1 ); 13 | } 14 | } ); 15 | test( 'logon and get root links for default services', async () => { 16 | let sall = 17 | process.env.DEFAULT_VIYA_SERVICES != null 18 | ? process.env.DEFAULT_VIYA_SERVICES 19 | : 'casManagement'; 20 | 21 | let sa = sall.split( ',' ).map( ( s1 ) => { 22 | return s1.trim(); 23 | } ); 24 | let s = sa.map( ( s1 ) => { 25 | return s1.trim(); 26 | } ); 27 | 28 | let l = await testFunctions.addServices( s, testInfo ); 29 | expect( l ).toMatchSnapshot(); 30 | } ); 31 | 32 | test( 'logon and get root links for VIYA_SERVICES env variable', async () => { 33 | 34 | // expect.assertions(); 35 | if ( process.env.VIYA_SERVICES != null ) { 36 | let s = process.env.VIYA_SERVICES.split( ',' ).map( ( s1 ) => { 37 | return s1.trim(); 38 | } ); 39 | let l = await testFunctions.addServices( s, testInfo ); 40 | expect( l ).toBe( 'done' ); 41 | } 42 | } ); 43 | -------------------------------------------------------------------------------- /packages/examples/cas.score.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | let testFunctions = require( './testFunctions' ); 19 | let testInfo; 20 | beforeAll( async () => { 21 | testInfo = await require( './lib/setupAll' )(); 22 | } ); 23 | 24 | test( 'Upload sasast and score', async () => { 25 | expect.assertions(); 26 | let l = await testFunctions.casScoreAst( false, testInfo ); 27 | expect( l ).toMatchSnapshot(); 28 | } ); 29 | 30 | 31 | test( 'Upload hdat and score', async () => { 32 | expect.assertions(); 33 | let l = await testFunctions.casScoreHdat( false, testInfo ); 34 | expect( l ).toMatchSnapshot(); 35 | } ); -------------------------------------------------------------------------------- /packages/examples/cas.sessions.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | let testFunctions = require( './testFunctions' ); 19 | let setupAll = require( './lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'CAS Session', async () => { 33 | let r = await testFunctions.casSession( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | test( 'Attach to an existing session', async () => { 38 | let r = await testFunctions.casSessionAttach( testInfo ); 39 | expect( r ).toBe( 'done' ); 40 | } ); 41 | 42 | -------------------------------------------------------------------------------- /packages/examples/compute.test.js: -------------------------------------------------------------------------------- 1 | let testFunctions = require( "./testFunctions" ); 2 | let testInfo; 3 | beforeAll( async () => { 4 | testInfo = await require( './lib/setupAll' )(); 5 | } ); 6 | test( "computeService: basic", async () => { 7 | expect.assertions(); 8 | let l = await testFunctions.computeDS( testInfo ); 9 | expect( l ).toMatchSnapshot(); 10 | } ); 11 | test( "computeTables: tables", async () => { 12 | expect.assertions(); 13 | let l = await testFunctions.computeTables( testInfo ); 14 | expect( l ).toMatchSnapshot(); 15 | } ); 16 | test.only( "computeTables: Attach", async () => { 17 | expect.assertions(); 18 | let l = await testFunctions.computeDSAttach( testInfo ); 19 | expect( l ).toMatchSnapshot(); 20 | } ); 21 | 22 | -------------------------------------------------------------------------------- /packages/examples/core.test.js: -------------------------------------------------------------------------------- 1 | let testFunctions = require( './testFunctions' ); 2 | let testInfo; 3 | beforeAll( async () => { 4 | try { 5 | testInfo = await require( './lib/setupAll' )(); 6 | } catch ( err ) { 7 | console.log( err ); 8 | process.exit( 1 ); 9 | } 10 | } ); 11 | test( 'identities service', async () => { 12 | let l = await testFunctions.identities( testInfo ); 13 | expect( l ).toMatchSnapshot(); 14 | } ); 15 | -------------------------------------------------------------------------------- /packages/examples/data/GBlocalcopy.sasast: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/packages/examples/data/GBlocalcopy.sasast -------------------------------------------------------------------------------- /packages/examples/data/GRADIENT_BOOSTING___BAD_2.sashdat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/packages/examples/data/GRADIENT_BOOSTING___BAD_2.sashdat -------------------------------------------------------------------------------- /packages/examples/data/LeNet_snzrle.astore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/packages/examples/data/LeNet_snzrle.astore -------------------------------------------------------------------------------- /packages/examples/data/cluster_test2.sas7bdat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/packages/examples/data/cluster_test2.sas7bdat -------------------------------------------------------------------------------- /packages/examples/data/paysimsvdd.sasast: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/packages/examples/data/paysimsvdd.sasast -------------------------------------------------------------------------------- /packages/examples/data/testdata.csv: -------------------------------------------------------------------------------- 1 | id,x1,x2,x3 2 | k1,1,2,3 3 | k2,2,3,4 4 | k3,5,6,7 5 | k4,6,7,30 6 | k5,7,3,4 7 | k6,8,9,0 8 | k7,1,2,3 9 | k8,2,3,4 10 | k9,5,6,7 11 | k11,1,2,3 12 | K21,2,3,4 13 | k31,5,6,7 14 | k41,6,7,30 15 | k51,7,3,4 16 | k61,8,9,0 17 | k71,1,2,3 18 | k81,2,3,4 19 | k91,5,6,7 20 | -------------------------------------------------------------------------------- /packages/examples/decisions.test.js: -------------------------------------------------------------------------------- 1 | let testFunctions = require( "./testFunctions" ); 2 | let testInfo; 3 | beforeAll( async () => { 4 | testInfo = await require( './lib/setupAll' )(); 5 | } ); 6 | test( "List repositories", async () => { 7 | expect.assertions(); 8 | let l = await testFunctions.modelRepoRoot( testInfo ); 9 | expect( l ).toMatchSnapshot(); 10 | } ); 11 | test.only( 'Create CAS Destination', async () => { 12 | expect.assertions(); 13 | let l = await testFunctions.modelDestinationCas( testInfo ); 14 | expect( l ).toMatchSnapshot(); 15 | } ); 16 | test( 'test mlPipeline', async () => { 17 | expect.assertions(); 18 | let l = await testFunctions.mlPipeline( testInfo ); 19 | expect( l ).toMatchSnapshot(); 20 | } ); 21 | test( 'test mlPipelinePublish', async () => { 22 | expect.assertions(); 23 | let l = await testFunctions.mlPipelinePublish( testInfo ); 24 | expect( l ).toMatchSnapshot(); 25 | } ); 26 | test.skip( 'test masList', async () => { 27 | expect.assertions(); 28 | let l = await testFunctions.masList( testInfo ); 29 | expect( l ).toMatchSnapshot(); 30 | } ); -------------------------------------------------------------------------------- /packages/examples/files.test.js: -------------------------------------------------------------------------------- 1 | let testFunctions = require( "./testFunctions" ); 2 | let testInfo; 3 | beforeAll( async () => { 4 | testInfo = await require( './lib/setupAll' )(); 5 | } ); 6 | test( "files: create and retrieve content", async () => { 7 | expect.assertions(); 8 | let l = await testFunctions.filesCreate( testInfo ); 9 | expect( l ).toMatchSnapshot(); 10 | } ); 11 | 12 | 13 | test( 'files - paginate thru files', async () => { 14 | expect.assertions(); 15 | let l = await testFunctions.filesPaginate( testInfo ); 16 | expect( l ).toMatchSnapshot(); 17 | } ); -------------------------------------------------------------------------------- /packages/examples/folders.test.js: -------------------------------------------------------------------------------- 1 | let testFunctions = require( "./testFunctions" ); 2 | let testInfo; 3 | beforeAll( async () => { 4 | testInfo = await require( './lib/setupAll' )(); 5 | } ); 6 | 7 | test( 'folders - paginate thru folders', async () => { 8 | expect.assertions(); 9 | let l = await testFunctions.foldersPaginate( testInfo ); 10 | expect( l ).toMatchSnapshot(); 11 | } ); -------------------------------------------------------------------------------- /packages/examples/lib/getToken.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * Recommend using viya-cli to setup token 9 | */ 10 | module.exports = function getToken(){ 11 | let fs = require('fs'); 12 | let j = fs.readFileSync(process.env.SASTOKEN, 'utf8'); 13 | let js = JSON.parse(j); 14 | let token = js.Default['access-token']; 15 | return token; 16 | } 17 | -------------------------------------------------------------------------------- /packages/examples/lib/listCaslibs.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved * * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * * you may not use this file except in compliance with the License. 5 | * * You may obtain a copy of the License at 6 | * * 7 | * * http://www.apache.org/licenses/LICENSE-2.0 8 | * * 9 | * * Unless required by applicable law or agreed to in writing, software 10 | * * distributed under the License is distributed on an "AS IS" BASIS, 11 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * ---------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 18 | 'use strict'; 19 | let print = require('.././print'); 20 | module.exports = async function listSessionTables(store, servers, session) { 21 | let casserver = servers.itemsList(0); 22 | let caslibs = await store.apiCall(servers.itemsCmd(casserver, 'caslibs')); 23 | 24 | // print.view(caslibs, 'caslibs'); 25 | for (let i = 0; i < caslibs.itemsList().size; i++) { 26 | let s = caslibs.itemsList(i); 27 | console.log(`========================caslib = ${s}`); 28 | let tables = await store.apiCall(caslibs.itemsCmd(s, 'tables')); 29 | let dataSets = tables.itemsList(); 30 | if ( dataSets.size > 0 ) { 31 | dataSets.map(t => console.log(t)); 32 | } else { 33 | console.log( 'No datasets in caslib'); 34 | } 35 | } 36 | }; -------------------------------------------------------------------------------- /packages/examples/lib/setupAll.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | let restaf = require('@sassoftware/restaf'); 7 | let configtest = require('./configtest'); 8 | module.exports = async function setupAll () { 9 | 10 | let payload = configtest(); 11 | let logger = require('./testLogger')(); 12 | 13 | 14 | let casopt = { 15 | casProxy: (process.env.CASPROXY === 'NO') ? false : true, 16 | options: { 17 | ns : (process.env.NAMESPACE != null && process.env.NAMESPACE.length > 0) ? process.env.NAMESPACE : null, 18 | proxyServer: (process.env.PROXYSERVER != null && process.env.PROXYSERVER.length > 0) ? process.env.PROXYSERVER : null, 19 | } 20 | }; 21 | 22 | console.log('casopt', casopt); 23 | debugger; 24 | let store = restaf.initStore(casopt); 25 | 26 | try { 27 | 28 | let msg = await store.logon(payload); 29 | console.log(msg); 30 | return { store: store, logonPayload: payload, logger: logger } 31 | } catch(err) { 32 | console.log(err); 33 | throw {error: "failed to logon"}; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /packages/examples/lib/testLogger.js: -------------------------------------------------------------------------------- 1 | const winston = require('winston'); 2 | module.exports = function testLogger () { 3 | let opts = { silent: (process.env.LOGGER !== 'YES'), prettyPrint: true }; 4 | let logger = winston.createLogger({ 5 | transports: [ 6 | new winston.transports.Console(opts) 7 | ] 8 | }); 9 | return logger; 10 | } 11 | -------------------------------------------------------------------------------- /packages/examples/notes/caslScore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sassoftware/restaf/44a360f743838e29ec9decc694661552f893ca6c/packages/examples/notes/caslScore.png -------------------------------------------------------------------------------- /packages/examples/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examples", 3 | "version": "5.3.0-alpha", 4 | "description": "Examples", 5 | "author": "Deva Kumaraswamy ", 6 | "license": "Apache-2.0", 7 | "keywords": [ 8 | "restaf", 9 | "SAS", 10 | "Viya", 11 | "REST API" 12 | ], 13 | "main": "index.js", 14 | "engines": { 15 | "node": ">=10.16.0", 16 | "npm": ">=6.10.0", 17 | "yarn": ">=1.17.3" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/sassoftware/restaf/tree/master/packages/examples" 22 | }, 23 | "bugs": { 24 | "url": "https://github.com/sassoftware/restaf/issues" 25 | }, 26 | "scripts": { 27 | "start": "node", 28 | "test": "cross-env RESTAFENV=.env NODE_TLS_REJECT_UNAUTHORIZED=0 npx jest", 29 | "debug": "cross-env RESTAFENV=.env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk ../../node_modules/jest/bin/jest.js --runInBand", 30 | "lint": "eslint . --fix", 31 | "dkrbuild": "docker build -f Dockerfile -t ruthere .", 32 | "dkrrun": "docker run --env-file ./override.env -t ruthere" 33 | }, 34 | "jest": { 35 | "testTimeout": 10000000, 36 | "verbose": false 37 | }, 38 | "dependencies": { 39 | "cross-env": "^7.0.3", 40 | "jest": "^27.5.0", 41 | "winston": "^3.2.1" 42 | }, 43 | "devDependencies": { 44 | "eslint": "^8.8.0", 45 | "microbundle": "^0.15.1" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/examples/puptests/basic.js: -------------------------------------------------------------------------------- 1 | let restaf = require( '@sassoftware/restaf' ); 2 | 3 | let store = restaf.initStore(); 4 | console.log( store.config ); 5 | let payload = { 6 | host : process.env.VIYA_PUP, 7 | token : 'xxxxx', 8 | tokenType: 'bearer', 9 | authType : 'server', 10 | options : { 11 | computeServerId: '0001' 12 | } 13 | 14 | } 15 | runtest ( store, payload ) 16 | .then ( r => console.log( r ) ) 17 | .catch( err => { 18 | 19 | console.log( JSON.stringify( err, null,4 ) ); 20 | } ); 21 | 22 | async function runtest( store, payload ) { 23 | 24 | let msg = await store.logon( payload ); 25 | console.log( msg ); 26 | let {compute} =await store.addServices( 'compute' ); 27 | console.log( 'compute created' ); 28 | let session = await store.apiCall( compute.links( 'createSession' ) ); 29 | 30 | let sascode = { 31 | data: { 32 | code: [ `data _null_; do i = 1 to 100; x=1; end; run; ` ], 33 | }, 34 | }; 35 | console.log( 'executing sas code' ); 36 | let job = await store.apiCall( session.links( "execute" ), sascode ); 37 | console.log( 'calling job status' ); 38 | let p = { 39 | qs: { 40 | newState: 'Completed', 41 | timeout : 5 42 | } 43 | } 44 | let status = await store.jobState( job, p ); 45 | 46 | if ( status.data === "running" ) { 47 | throw `ERROR: Job did not complete in allotted time`; 48 | } else { 49 | switch ( status.data ) { 50 | case "warning": 51 | console.log( `Warning: check your log for warnings` ); 52 | break; 53 | case "error": 54 | throw `Please correct errors and rerun program`; 55 | default: 56 | let log = await store.apiCall( status.job.links( "log" ) ); 57 | console.log( log.items().toJS() ); 58 | break; 59 | } 60 | } 61 | return true; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /packages/examples/puptests/easy.js: -------------------------------------------------------------------------------- 1 | let restaf = require( '@sassoftware/restaf' ); 2 | let restaflib = require( '@sassoftware/restaflib' ); 3 | 4 | let store = restaf.initStore(); 5 | let payload = { 6 | host : process.env.VIYA_PUP, 7 | token : 'xxxxx', 8 | tokenType: 'bearer', 9 | authType : 'server', 10 | options : { 11 | computeServerId: '0001' 12 | } 13 | 14 | } 15 | runtest ( store, payload ) 16 | .then ( r => console.log( r ) ) 17 | .catch( err => { 18 | 19 | console.log( JSON.stringify( err, null,4 ) ); 20 | } ); 21 | 22 | async function runtest( store, payload ) { 23 | 24 | console.log( store.config ); 25 | let computeSession = await restaflib.computeSetup( store, null, payload ); 26 | console.log( store.store.config ); 27 | 28 | let macros = { 29 | x1: 10, 30 | x2: 20 31 | }; 32 | let src = ` 33 | ods html style=barrettsblue; 34 | %let x1=10; 35 | %let x2=20; 36 | data work.dtemp1; 37 | total = &x1 + &x2; 38 | run; 39 | proc print;run; 40 | ods html close; 41 | run; 42 | `; 43 | let computeSummary = await restaflib.computeRun( 44 | store, 45 | computeSession, 46 | src, 47 | macros 48 | /* 49 | 15, 50 | 5 51 | */ 52 | ); 53 | 54 | // Fetch data 55 | data = await restaflib.computeFetchData( 56 | store, 57 | computeSummary, 58 | "DTEMP1", 59 | "next", 60 | { offset: 0, limit: 1 } 61 | ); 62 | console.log( JSON.stringify( data, null,4 ) ); 63 | 64 | // show log 65 | let log = await restaflib.computeResults( store, computeSummary, "log" ); 66 | console.log( JSON.stringify( log, null, 4 ) ); 67 | 68 | // show ods 69 | let ods = await restaflib.computeResults( store, computeSummary, "ods" ); 70 | // console.log(ods); 71 | return 'done'; 72 | 73 | } 74 | -------------------------------------------------------------------------------- /packages/examples/scripts/start.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo "Starting app" 3 | set -x 4 | exec 5 | -------------------------------------------------------------------------------- /packages/examples/start.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo "Starting app" 3 | set -x 4 | echo $VIYA_SERVER 5 | echo $CASPROXY 6 | exec npx jest -- $TESTS 7 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/addServices.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | "use strict"; 18 | 19 | /* -------------------------------------------------------------------------------- 20 | * Logon to the restaf server and setup multiple services 21 | * --------------------------------------------------------------------------------- 22 | */ 23 | 24 | let restaf = require( '@sassoftware/restaf' ); 25 | let {lib} = require( '@sassoftware/restaflib' ); 26 | module.exports = async function addServices ( args, testInfo ) { 27 | let { store, logger } = testInfo; 28 | let s = await store.addServices( ...args ); 29 | let l = Object.keys( s ); 30 | logger.info( l, 'list of services' ); 31 | 32 | // test adding existing service 33 | let s1 = args[ 0 ]; 34 | let t1 = await store.addServices( s1 ); 35 | 36 | /* test calling addServies multiple times on the same service */ 37 | await store.addServices( 'reports', 'dataMining' ); 38 | console.log( store.getServices() ); 39 | console.log( lib.computeResults ); 40 | 41 | 42 | return 'done'; 43 | 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/addServices2.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | /* 18 | * Simple echo action example 19 | */ 20 | "use strict"; 21 | 22 | let { casSetup, caslRun} = require( '@sassoftware/restaflib' ); 23 | 24 | module.exports = async function casEcho ( testInfo ) { 25 | let { store, logger } = testInfo; 26 | debugger; 27 | let x = await store.addServices('casManagement'); 28 | console.log(JSON.stringify(store.getXsrfData())); 29 | 30 | return 'done'; 31 | }; 32 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/appData.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | /* 18 | * Simple echo action example 19 | */ 20 | "use strict"; 21 | 22 | let { casSetup} = require( '@sassoftware/restaflib' ); 23 | 24 | module.exports = async function casEcho ( testInfo ) { 25 | let { store, logger } = testInfo; 26 | let { session } = await casSetup( store, null ); 27 | logger.info( session.items().toJS() ); 28 | 29 | store.setAppData( 'casSession' , session ); 30 | 31 | let t = store.getAppData(); 32 | console.log( t ); 33 | 34 | 35 | await store.apiCall( session.links( 'delete' ) ); 36 | return 'done'; 37 | }; 38 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/casDSLoad.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved * Licensed under the Apache License, Version 2.0 (the 'License'); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an 'AS IS' BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * --------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 18 | /* 19 | * Run a cas data step and then retrieve the created table 20 | */ 21 | 'use strict'; 22 | 23 | let { casSetup, casLoadTable} = require( '@sassoftware/restaflib' ); 24 | 25 | module.exports = async function casDSLoad ( testInfo ) { 26 | let { store, logger } = testInfo; 27 | debugger; 28 | let { session } = await casSetup( store, null ); 29 | 30 | let actionPayload = { 31 | action: 'datastep.runCode', 32 | data : { 33 | single: 'YES', 34 | code : 35 | 'data casuser.score; keep x1 x2;do i = 1 to 20; x1=i; x2=i*10;output;end;run; ' 36 | } 37 | }; 38 | debugger; 39 | await store.runAction( session, actionPayload ); 40 | 41 | let table = { 42 | caslib: 'casuser' /* a valid caslib */, 43 | name : 'score' 44 | }; 45 | 46 | let r = await casLoadTable( store, session, table ); 47 | console.log( r ); 48 | 49 | 50 | await store.apiCall( session.links( 'delete' ) ); 51 | return 'done'; 52 | }; 53 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/casScoreAst.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved * Licensed under the Apache License, Version 2.0 (the 'License'); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an 'AS IS' BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * --------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let restaflib = require( '@sassoftware/restaflib' ); 21 | let { casSetup, casUpload, caslDescribe, caslScore} = restaflib; 22 | 23 | module.exports = async function casScoreAst ( save, testInfo ) { 24 | let { store, logger } = testInfo; 25 | let { session } = await casSetup( store, null ); 26 | let r = await casUpload( 27 | store, 28 | session, 29 | './data/paysimsvdd.sasast', 30 | 'casuser.paysimjest', 31 | save 32 | ); 33 | 34 | let scenario = { 35 | model : { caslib: 'casuser', name: 'paysimjest' }, 36 | scenario: { 37 | type_n : 1, 38 | amount : 10000, 39 | newbalanceDest: 1000, 40 | newbalanceOrig: 1000, 41 | oldbalanceDest: 1000, 42 | oldbalanceOrg : 1000, 43 | isFraud : 0 44 | } 45 | }; 46 | 47 | r = await caslDescribe( store, session, scenario ); 48 | 49 | let desc = r.casResults.describe; 50 | 51 | r = await caslScore( store, session, scenario ); 52 | 53 | 54 | let result = { 55 | describe: desc, 56 | score : r 57 | }; 58 | logger.info( result ); 59 | await store.apiCall( session.links( 'delete' ) ); 60 | return result; 61 | 62 | }; 63 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/casScoreAstFail.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved * Licensed under the Apache License, Version 2.0 (the 'License'); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an 'AS IS' BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * --------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let restaflib = require( '@sassoftware/restaflib' ); 21 | let { casSetup, casUpload, caslDescribe, caslScore, print } = restaflib; 22 | 23 | module.exports = async function casScoreAstFail ( save, testInfo ) { 24 | let { store, logger } = testInfo; 25 | let { session } = await casSetup( store, null ); 26 | let r = await casUpload( 27 | store, 28 | session, 29 | './data/paysimsvdd.sasast', 30 | 'casuser.paysimjest', 31 | save 32 | ); 33 | 34 | let scenario = { 35 | model : { caslib: 'casuser', name: 'paysimjestx' }, 36 | scenario: { 37 | type_n : 1, 38 | amount : 10000, 39 | newbalanceDest: 1000, 40 | newbalanceOrig: 1000, 41 | oldbalanceDest: 1000, 42 | oldbalanceOrg : 1000, 43 | isFraud : 0 44 | } 45 | }; 46 | 47 | try { 48 | r = await caslScore( store, session, scenario ); 49 | } 50 | catch ( err ) { 51 | logger.info( err ); 52 | return 'done'; 53 | } 54 | 55 | let result = { 56 | score: r 57 | }; 58 | logger.info( result ); 59 | await store.apiCall( session.links( 'delete' ) ); 60 | return result; 61 | 62 | }; 63 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/casScoreHdat.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved * Licensed under the Apache License, Version 2.0 (the 'License'); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an 'AS IS' BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * --------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let restaflib = require( '@sassoftware/restaflib' ); 21 | let { casSetup, casUpload, caslScore} = restaflib; 22 | 23 | module.exports = async function casScoreHdat ( save, testInfo ) { 24 | let { store, logger } = testInfo; 25 | let { session } = await casSetup( store, null ); 26 | 27 | let r = await casUpload( 28 | store, 29 | session, 30 | './data/GRADIENT_BOOSTING___BAD_2.sashdat', 31 | 'casuser.GRADIENT_BOOSTING___BAD_2jest', 32 | save 33 | ); 34 | 35 | let scenario = { 36 | model : { caslib: 'casuser', name: 'gradient_boosting___bad_2jest' }, 37 | scenario: { 38 | LOAN : 100000, 39 | VALUE : 10000, 40 | JOB : 'J1', 41 | CLAGE : 100, 42 | CLNO : 20, 43 | DEBTINC: 20, 44 | DELINQ : 2, 45 | DEROG : 0, 46 | MORTDUE: 4000, 47 | NINQ : 1, 48 | YOJ : 10 49 | } 50 | }; 51 | 52 | r = await caslScore( store, session, scenario ); 53 | logger.info( r ); 54 | await store.apiCall( session.links( 'delete' ) ); 55 | return r; 56 | }; 57 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/casSession.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | "use strict"; 6 | 7 | let restaflib = require("@sassoftware/restaflib"); 8 | module.exports = async function casSession(testInfo) { 9 | let { store, logger } = testInfo; 10 | console.log("config", store.config); 11 | let { session } = await restaflib.casSetup( 12 | store, 13 | null, 14 | null, 15 | null 16 | ); 17 | 18 | //console.log( session.links( 'execute' ).toJS() ); 19 | //logger.info( session.items().toJS() ); 20 | 21 | let p1 = { 22 | action: "datastep.runCode", 23 | data: { 24 | single: "YES", 25 | code: "data casuser.score; keep x1 x2;do i = 1 to 20; x1=i; x2=i*10;output;end;run; ", 26 | }, 27 | }; 28 | debugger; 29 | let r1 = await store.runAction(session, p1); 30 | console.log(r1.details().toJS()); 31 | /* 32 | console.log(r1.items().toJS()); 33 | console.log(r1.results().toJS()); 34 | */ 35 | 36 | console.log("---------------------------"); 37 | /* 38 | let p = { 39 | action: "builtins.echo", 40 | data: { 41 | code: "data casuser.score; x1=10;x2=20;x3=30; score1 = x1+x2+x3;run; ", 42 | }, 43 | }; 44 | logger.info(p); 45 | 46 | let r = await store.runAction(session, p); 47 | console.log( JSON.stringify( session.links( "execute" ), null, 4 ) ); 48 | console.log(r.items().toJS()); 49 | */ 50 | await store.apiCall(session.links("delete")); 51 | return "done"; 52 | }; 53 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/casSessionAttach.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | 7 | let restaflib = require( '@sassoftware/restaflib' ); 8 | module.exports = async function casSessionAttach ( testInfo ) { 9 | let {store, logger} = testInfo; 10 | let { session } = await restaflib.casSetup( store, null ); 11 | 12 | let sessionID = session.items( 'id' ); 13 | console.log( sessionID ); 14 | 15 | let r = await restaflib.casSetup( store, null, sessionID ); 16 | console.log( r ); 17 | let sessionID2 = r.session.items( 'id' ); 18 | console.log( sessionID2 ); 19 | console.log( r.session.links().toJS() ); 20 | 21 | return 'done'; 22 | }; 23 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/casSubmit.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | /* 18 | * Simple echo action example 19 | */ 20 | "use strict"; 21 | 22 | let { casSetup} = require( '@sassoftware/restaflib' ); 23 | 24 | module.exports = async function casSubmit ( testInfo ) { 25 | let { store, logger } = testInfo; 26 | let { session } = await casSetup( store, null ); 27 | logger.info( session.items().toJS() ); 28 | 29 | let p = { 30 | action: 'builtins.echo', 31 | data : { 32 | code: 'data casuser.score; do i = 1 to 10; x1=10;x2=20;x3=30; score1 = x1+x2+x3;end; run; ' 33 | } 34 | }; 35 | 36 | logger.info( p ); 37 | 38 | const progress = ( status, jobContext ) => { 39 | console.log( 'progress ', status ); 40 | return ( status.items.isIdle === false ); 41 | } 42 | 43 | // let r = await store.runAction(session, p,'AAA', null,'wait',5,progress); 44 | 45 | let r = await store.runAction( session, p ); 46 | logger.info( r ); 47 | await store.apiCall( session.links( 'delete' ) ); 48 | return 'done'; 49 | }; 50 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/casUnique.js: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------------------ 3 | Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved Licensed under the Apache License, Version 2.0 (the 'License'); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | * 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an 'AS IS' BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | --------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 18 | /* 19 | Run a cas data step and then retrieve the created table 20 | */ 21 | 'use strict'; 22 | 23 | let { casSetup, caslRun} = require( '@sassoftware/restaflib' ); 24 | 25 | module.exports = async function casUnique( testInfo ) { 26 | let {store, logger} = testInfo; 27 | let { session } = await casSetup( store ); 28 | 29 | const src = ` 30 | results = selectionLists(_args_.column ,_args_.table.caslib, _args_.table.name, _args_.where); 31 | send_response({casResults = {data=results}}); 32 | ` 33 | let payload = { 34 | column: [ 'make' ], 35 | where : `origin eq 'USA' and type eq 'Truck'`, 36 | table : { caslib: 'casuser', name: 'cars' }, 37 | 38 | }; 39 | 40 | let r = await caslRun( store,session, src, payload, true ); 41 | console.log( r.results.casResults.data ); 42 | return 'done'; 43 | } 44 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/casUploadAst.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved * Licensed under the Apache License, Version 2.0 (the 'License'); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an 'AS IS' BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * --------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let restaflib = require( '@sassoftware/restaflib' ); 21 | let { casSetup, casUpload, caslDescribe} = restaflib; 22 | 23 | module.exports = async function casUploadAst ( save, testInfo ) { 24 | let { store, logger } = testInfo; 25 | 26 | let { session } = await casSetup( store, null ); 27 | 28 | let r = await casUpload( 29 | store, 30 | session, 31 | './data/paysimsvdd.sasast', 32 | 'casuser.paysimjest', 33 | save 34 | ); 35 | 36 | let scenario = { 37 | model : { caslib: 'casuser', name: 'paysimjest' }, 38 | scenario: { 39 | type_n : 1, 40 | amount : 10000, 41 | newbalanceDest: 1000, 42 | newbalanceOrig: 1000, 43 | oldbalanceDest: 1000, 44 | oldbalanceOrg : 1000, 45 | isFraud : 0 46 | } 47 | }; 48 | 49 | r = await caslDescribe( store, session, scenario ); 50 | 51 | let desc = r.casResults.describe; 52 | 53 | logger.info( desc ); 54 | await store.apiCall( session.links( 'delete' ) ); 55 | 56 | return desc; 57 | 58 | }; -------------------------------------------------------------------------------- /packages/examples/testFunctions/casUploadCsv2.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved * Licensed under the Apache License, Version 2.0 (the 'License'); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an 'AS IS' BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * --------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 18 | 'use strict'; 19 | 20 | 21 | let restaflib = require( '@sassoftware/restaflib' ); 22 | let { casSetup, casUpload} = restaflib; 23 | 24 | module.exports = async function casUploadCsv2 ( save, testInfo ) { 25 | let { store, logger } = testInfo; 26 | let { session } = await casSetup( store, null ); 27 | 28 | let r = await casUpload( 29 | store, 30 | session, 31 | './data/cars.csv', 32 | 'casuser.carsnew', 33 | save 34 | ); 35 | // run fetch action 36 | let actionPayload = { 37 | action: 'table.fetch', 38 | data : { 39 | table: { 40 | caslib: 'casuser', 41 | name : 'carsnew' 42 | } 43 | } 44 | }; 45 | let actionResult = await store.runAction( session, actionPayload ); 46 | 47 | logger.info( actionResult.items( 'tables' ) ); 48 | let t = actionResult.items( 'tables', 'Fetch' ).toJS(); 49 | t.attributes.CreateTime.value = 0.0; 50 | await store.apiCall( session.links( 'delete' ) ); 51 | return t; 52 | }; 53 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/casUploadProgram2.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved * Licensed under the Apache License, Version 2.0 (the 'License'); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an 'AS IS' BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * --------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let restaflib = require( '@sassoftware/restaflib' ); 21 | let { casSetup, casUpload } = restaflib; 22 | 23 | module.exports = async function casUploadProgram2 ( save,testInfo ) { 24 | let { store, logger } = testInfo; 25 | 26 | let { session } = await casSetup( store, null ); 27 | 28 | let r = await casUpload( 29 | store, 30 | session, 31 | './data/test2.sas', 32 | 'casuser.testjest', 33 | save 34 | ); 35 | // run fetch action 36 | let actionPayload = { 37 | action: 'table.fetch', 38 | data : { 39 | table: { 40 | caslib: 'casuser', 41 | name : 'testjest' 42 | } 43 | } 44 | }; 45 | let actionResult = await store.runAction( session, actionPayload ); 46 | 47 | // print.object(actionResult.items('tables'), 'Fetched data'); 48 | let t = actionResult.items( 'tables', 'Fetch' ).toJS(); 49 | t.attributes.CreateTime.value = 0.0; 50 | await store.apiCall( session.links( 'delete' ) ); 51 | return t; 52 | }; 53 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/casUploadbdat.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved * Licensed under the Apache License, Version 2.0 (the 'License'); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an 'AS IS' BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * --------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let restaflib = require( '@sassoftware/restaflib' ); 21 | let { casSetup, casUpload} = restaflib; 22 | 23 | module.exports = async function casUploadbdat ( save, testInfo ) { 24 | let { store } = testInfo; 25 | let { session } = await casSetup( store, null ); 26 | 27 | let r = await casUpload( 28 | store, 29 | session, 30 | './data/cluster_test2.sas7bdat', 31 | 'casuser.cluster_test2jest', 32 | save 33 | ); 34 | // run fetch action 35 | let actionPayload = { 36 | action: 'table.fetch', 37 | data : { 38 | table: { 39 | caslib: 'casuser', 40 | name : 'cluster_test2jest' 41 | } 42 | } 43 | }; 44 | let actionResult = await store.runAction( session, actionPayload ); 45 | 46 | // print.object(actionResult.items('tables'), 'Fetched data'); 47 | let t = actionResult.items( 'tables', 'Fetch' ).toJS(); 48 | t.attributes.CreateTime.value = 0.0; 49 | await store.apiCall( session.links( 'delete' ) ); 50 | return t; 51 | }; 52 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/casUploadhdat.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved * Licensed under the Apache License, Version 2.0 (the 'License'); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an 'AS IS' BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * --------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 18 | 'use strict'; 19 | 20 | 21 | let restaflib = require( '@sassoftware/restaflib' ); 22 | let { casSetup, casUpload } = restaflib; 23 | 24 | module.exports = async function casUploadbdat ( save, testInfo ) { 25 | let { store } = testInfo; 26 | let { session } = await casSetup( store, null ); 27 | 28 | let r = await casUpload( 29 | store, 30 | session, 31 | './data/GRADIENT_BOOSTING___BAD_2.sashdat', 32 | 'casuser.GRADIENT_BOOSTING___BAD_2jest', 33 | save 34 | ); 35 | await store.apiCall( session.links( 'delete' ) ); 36 | return 'done'; 37 | }; 38 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/filesCreate.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | 7 | module.exports = async function createFile ( testInfo ) { 8 | let { store, logger } = testInfo; 9 | let { files } = await store.addServices( 'files' ); 10 | let name = 'geekname'; 11 | let payload = { 12 | data : { me: 'hi there'}, 13 | headers: { 14 | // 'Content-Disposition': `inline; form-data; filename=${name} name=${name}`, 15 | 'Content-Disposition': `text/plain`, 16 | 'content-type' : `text/plain` 17 | } 18 | }; 19 | //create a file 20 | let createCmd = files.links( 'create' ); 21 | let newFile = await store.apiCall( createCmd, payload ); 22 | let c = await store.apiCall( newFile.links( 'content' ) ); 23 | logger.info( c.items() ); 24 | let uri = newFile.links( 'self', 'link', 'uri' ); 25 | logger.info( uri ); 26 | 27 | // set name and other attributes 28 | let p = { 29 | data: { 30 | name : name, 31 | description: 'stuff', 32 | properties : { 33 | newprop: 'tttt' 34 | } 35 | }, 36 | headers: { 37 | 'if-unmodified-since': newFile.headers( 'last-modified' ) 38 | } 39 | } 40 | 41 | console.log( 'after update' ); 42 | 43 | let updated = await store.apiCall( newFile.links( 'update' ), p ); 44 | console.log( updated.items().toJS() ); 45 | 46 | p = { 47 | qs: { 48 | filter: `contains(name, "${name}")` 49 | } 50 | }; 51 | let selection = await store.apiCall( files.links( 'files' ), p ); 52 | console.log( selection.itemsList().toJS() ); 53 | 54 | return 'done'; 55 | 56 | }; 57 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/filesPaginate.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | "use strict"; 18 | 19 | // Pagination 20 | 21 | module.exports = async function filesPaginate ( testInfo ) { 22 | let { store, logger } = testInfo; 23 | 24 | let { files } = await store.addServices( "files" ); 25 | 26 | let filesList = await store.apiCall( files.links( "files" ) ); 27 | console.log( JSON.stringify( filesList.itemsList().toJS(), null,4 ) ); 28 | 29 | let next; 30 | // do this loop while the service returns the next link or counter is 0 31 | 32 | while ( ( next = filesList.scrollCmds( "next" ) ) !== null ) { 33 | filesList = await store.apiCall( next ); 34 | let l = filesList.itemsList().toJS(); 35 | console.log( JSON.stringify( l, null,4 ) ); 36 | } 37 | 38 | 39 | return "done"; 40 | }; 41 | 42 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/identities.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * ------------------------------------------------------------------------------------ 4 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * --------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 18 | 19 | module.exports = async function identities ( testInfo ) { 20 | let { store, logger } = testInfo; 21 | let { identities } = await store.addServices( 'identities' ); 22 | let c = await store.apiCall( identities.links( 'currentUser' ) ); 23 | logger.info( c.items() ); 24 | let a = await store.apiCall( identities.links( 'currentUserAdmin' ) ); 25 | logger.info( a.items() ); 26 | return 'done'; 27 | }; 28 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/logonTest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | /* -------------------------------------------------------------------------------- 19 | * Logon to the Viya server 20 | * --------------------------------------------------------------------------------- 21 | */ 22 | let restaf = require( '@sassoftware/restaf' ); 23 | let { print, decodeJwt } = require( '@sassoftware/restaflib' ); 24 | module.exports = async function logonTest () { 25 | let payload = require( '../lib/config' )(); 26 | payload.keepAlive = null; 27 | 28 | let store = restaf.initStore(); 29 | 30 | console.log( 'in logonTest' ); 31 | 32 | store 33 | .logon( payload ) 34 | .then( msg => { 35 | console.log( JSON.stringify( store.connection(), null, 4 ) ); 36 | let token = store.connection().token; 37 | process.env.VIYA_TOKEN = token; 38 | let jwt = decodeJwt( token ); 39 | print.object( jwt, 'JWT' ); 40 | console.log( `Logon Status: ${msg}` ); 41 | let c = store.connection(); 42 | print.object( c, 'Connection information' ); 43 | return 'done'; 44 | } ) 45 | .catch( err => console.log( err ) ); 46 | 47 | }; -------------------------------------------------------------------------------- /packages/examples/testFunctions/masScore.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved * Licensed under the Apache License, Version 2.0 (the 'License'); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an 'AS IS' BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * --------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 18 | 'use strict'; 19 | 20 | let restaflib = require( '@sassoftware/restaflib' ); 21 | let { masDescribe, masRun } = restaflib; 22 | 23 | module.exports = async function masScore ( testInfo ) { 24 | let { store, logger } = testInfo; 25 | let { microanalyticScore } = await store.addServices( 'microanalyticScore' ); 26 | let modelList1 = await store.apiCall( microanalyticScore.links( 'modules' ) ); 27 | console.log( JSON.stringify( modelList1.itemsList(), null, 4 ) ); 28 | 29 | // let models = ['LogisticRegression_f726351799f44e2d927a40c950047331']; 30 | let models = [ 'machine2_0' ] 31 | 32 | let masControl = await restaflib.masSetup( store, models ); 33 | console.log( JSON.stringify( masControl, 1,4 ) ); 34 | 35 | let desc = masDescribe( masControl, models[0] ); 36 | console.log( desc ); 37 | 38 | 39 | let scenario = {}; 40 | desc.map( ( d,i ) => { 41 | scenario[d.name] = 100; 42 | } ); 43 | 44 | logger.info( scenario ); 45 | 46 | let result = await masRun( store, masControl, models[ 0 ], scenario, null, 'execute' ); 47 | logger.info( result ); 48 | console.log( JSON.stringify( result, null,4 ) ); 49 | return 'done'; 50 | }; 51 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/mlPipeline.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | module.exports = async function mlPipeline ( testInfo ){ 7 | let { store, logger } = testInfo; 8 | let { mlPipelineAutomation} = await store.addServices( 'mlPipelineAutomation' ); 9 | let l = mlPipelineAutomation.links().keySeq(); 10 | console.log( JSON.stringify( l, null,4 ) ); 11 | 12 | 13 | let projects = await store.apiCall( mlPipelineAutomation.links( 'collection' ) ); 14 | let size = projects.itemsList().size; 15 | console.log( size ); 16 | let x = projects.itemsCmd( projects.itemsList( 0 ) ).keySeq(); 17 | console.log( JSON.stringify( x,null,4 ) ); 18 | // console.log(JSON.stringify(projects.itemsCmd(projects.itemsList(0)),null,4)); 19 | let next; 20 | while ( ( next = projects.scrollCmds( "next" ) ) !== null ) { 21 | projects = await store.apiCall( next ); 22 | let x = projects.itemsCmd( projects.itemsList( 0 ) ).keySeq(); 23 | console.log( JSON.stringify( x,null,4 ) ); 24 | } 25 | /* 26 | if (size > 0) { 27 | let m = projects.itemsList(0); 28 | console.log(`>>> ${m}`); 29 | console.log(JSON.stringify(projects.items(m, 'data'),null,4)); 30 | let k = projects.itemsCmd(m).keySeq(); 31 | console.log(JSON.stringify(k, null,4)); 32 | let raflink = projects.items(m,'data', 'championModel'); 33 | console.log(JSON.stringify(raflink, null,4)); 34 | 35 | 36 | let detail = []; 37 | k.forEach (k1 => { 38 | let link = projects.itemsCmd(m, k1,'link','uri'); 39 | console.log(`${k1}, ${link}`); 40 | let row = {rel: k1, uri: link}; 41 | detail.push(row); 42 | }) 43 | console.log(JSON.stringify(detail, null,4)); 44 | } 45 | */ 46 | 47 | 48 | 49 | return 'done'; 50 | }; 51 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/mlPipelinePublish.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | module.exports = async function mlPipelinePublish ( testInfo ){ 7 | let { store, logger } = testInfo; 8 | let { mlPipelineAutomation} = await store.addServices( 'mlPipelineAutomation' ); 9 | let l = mlPipelineAutomation.links().keySeq(); 10 | console.log( JSON.stringify( l, null,4 ) ); 11 | 12 | let projects = await store.apiCall( mlPipelineAutomation.links( 'collection' ) ); 13 | let size = projects.itemsList().size; 14 | console.log( size ); 15 | 16 | let payload = { 17 | qs: { 18 | action : 'publish', 19 | destinationName: 'maslocal' 20 | }, 21 | headers: { 22 | Accept: 'application/vnd.sas.analytics.ml.pipeline.automation.project+json' 23 | } 24 | }; 25 | 26 | if ( projects.itemsList().size > 0 ){ 27 | let rafLink = projects.itemsCmd( projects.itemsList( 0 ), 'publishChampionModel' ); 28 | 29 | let r = await store.apiCall( rafLink,payload ); 30 | console.log( r.headers( 'location' ) ); 31 | } else { 32 | console.log( 'No models found' ); 33 | } 34 | 35 | 36 | 37 | return 'done'; 38 | 39 | }; 40 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/modelDestinationCas.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | 7 | let uuid = require( 'uuid' ); 8 | module.exports = async function modelDestinationCas ( testInfo ){ 9 | let { store, logger } = testInfo; 10 | let { modelPublish } = await store.addServices( 'modelPublish' ); 11 | // logger.info(modelPublish.links().keySeq()); 12 | 13 | let r = await store.apiCall( modelPublish.links( 'destinations' ) ); 14 | // logger.info(r); 15 | logger.info( r.itemsList() ); 16 | if ( r.itemsList( 'testPublishjest' ) !== null ) { 17 | logger.info( 'testPublishjest exists' ); 18 | await store.apiCall( r.itemsCmd( 'testPublishjest', 'delete' ) ); 19 | } 20 | let payload = { 21 | data: { 22 | 23 | name : 'testPublishjestx', 24 | casServerName : 'cas-shared-default', 25 | casLibrary : 'Public', 26 | destinationTable: 'jest' + uuid.v1(), 27 | destinationType : 'cas' 28 | } 29 | }; 30 | logger.info( payload ); 31 | r = await store.apiCall( modelPublish.links( 'createDestinationCAS' ), payload ); 32 | logger.info( 'after create' ); 33 | logger.info( r.items() ); 34 | 35 | let newList = await store.apiCall( modelPublish.links( 'destinations' ) ); 36 | logger.info( newList.itemsList() ); 37 | 38 | // now upload a sasast and then try to publish it to the new cas destination 39 | 40 | await store.apiCall( newList.itemsCmd( 'testPublishjestx', 'delete' ) ); 41 | 42 | 43 | return 'done'; 44 | }; 45 | -------------------------------------------------------------------------------- /packages/examples/testFunctions/modelRepoRoot.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | module.exports = async function modelRepoRoot ( testInfo ){ 7 | let { store, logger } = testInfo; 8 | let { modelRepository } = await store.addServices( 'modelRepository' ); 9 | 10 | let rels = modelRepository.links().keySeq(); 11 | logger.info( rels ); 12 | return 'done'; 13 | }; 14 | -------------------------------------------------------------------------------- /packages/restaf/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env" 4 | ], 5 | "plugins": [ 6 | "@babel/plugin-transform-regenerator", 7 | "@babel/plugin-transform-runtime", 8 | "@babel/plugin-syntax-dynamic-import", 9 | "@babel/plugin-syntax-import-meta", 10 | "@babel/plugin-proposal-class-properties", 11 | "@babel/plugin-proposal-json-strings", 12 | [ 13 | "@babel/plugin-proposal-decorators", 14 | { 15 | "legacy": true 16 | } 17 | ], 18 | "@babel/plugin-proposal-function-sent", 19 | "@babel/plugin-proposal-export-namespace-from", 20 | "@babel/plugin-proposal-numeric-separator", 21 | "@babel/plugin-proposal-throw-expressions", 22 | "@babel/plugin-proposal-export-default-from", 23 | "@babel/plugin-proposal-logical-assignment-operators", 24 | "@babel/plugin-proposal-optional-chaining", 25 | [ 26 | "@babel/plugin-proposal-pipeline-operator", 27 | { 28 | "proposal": "minimal" 29 | } 30 | ], 31 | "@babel/plugin-proposal-nullish-coalescing-operator", 32 | "@babel/plugin-proposal-do-expressions", 33 | "@babel/plugin-proposal-function-bind", 34 | "@babel/plugin-proposal-object-rest-spread" 35 | ] 36 | } -------------------------------------------------------------------------------- /packages/restaf/jsdoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["plugins/markdown"], 3 | "recurseDepth": 10, 4 | "source": { 5 | "include": ["./"], 6 | "includePattern": ".jsdoc$", 7 | "excludePattern": "(node_modules/|docs)" 8 | }, 9 | "templates": { 10 | "cleverLinks": true, 11 | "monospaceLinks": true 12 | }, 13 | "opts": { 14 | "destination": "../../docs/restaf", 15 | "recurse": true, 16 | "readme": "./README.md" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/restaf/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@sassoftware/restaf", 3 | "version": "5.3.0-alpha.0", 4 | "description": "Library for writing SAS Viya application using REST APIs", 5 | "author": "Deva Kumaraswamy ", 6 | "license": "Apache-2.0", 7 | "keywords": [ 8 | "restaf", 9 | "SAS", 10 | "Viya", 11 | "REST API" 12 | ], 13 | "homepage": "https://github.com/sassoftware/restaf#README.md", 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/sassoftware/restaf/tree/main/packages/restaf" 17 | }, 18 | "bugs": { 19 | "url": "https://github.com/sassoftware/restaf/issues" 20 | }, 21 | "unpkg": "/dist/restaf.min.js", 22 | "main": "./lib/restaf.js", 23 | "modules": "/dist/restaf.min.js", 24 | "browser": "/dist/restaf.min.js", 25 | "files": [ 26 | "lib", 27 | "dist" 28 | ], 29 | "engines": { 30 | "node": ">=10.16.0", 31 | "npm": ">=6.10.0", 32 | "yarn": ">=1.17.3" 33 | }, 34 | "browserslist": [ 35 | "last 2 versions", 36 | "ie >= 11", 37 | "maintained node versions" 38 | ], 39 | "scripts": { 40 | "test": "node", 41 | "build": "rimraf dist && rimraf lib && webpack --env target=node p=n --config webpack.config.js && webpack --env target=web p=n --config webpack.config.js && webpack --env target=web p=y --config webpack.config.js", 42 | "babel": "babel src --out-dir jslib", 43 | "pub": "npm publish --tag alpha --access public", 44 | "lint": "eslint . --fix", 45 | "jsdoc": "jsdoc -c jsdoc.json", 46 | "dlink": "npm link", 47 | "bump": "npm version prerelease" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/restaf/src/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | import {initStore, endStore, restoreStore} from './store'; 17 | export { initStore, endStore, restoreStore }; 18 | 19 | -------------------------------------------------------------------------------- /packages/restaf/src/reducers/createReducer.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | import {combineReducers} from 'redux'; 7 | 8 | import baseReducer from './baseReducer'; 9 | import viyaLogon from './viyaLogon'; 10 | 11 | import {APP_DATA_ROOT, API_STATUS_ROOT, API_XSRF_ROOT} from '../actionTypes'; 12 | 13 | const createReducer = ( asyncReducer ) => { 14 | 15 | let reducerList = {}; 16 | reducerList['connections'] = viyaLogon; 17 | reducerList[API_STATUS_ROOT] = baseReducer( API_STATUS_ROOT ); 18 | reducerList[APP_DATA_ROOT] = baseReducer( APP_DATA_ROOT ); 19 | reducerList[API_XSRF_ROOT] = baseReducer( API_XSRF_ROOT ); 20 | 21 | reducerList = {...reducerList, ...asyncReducer}; 22 | return combineReducers ( reducerList ); 23 | 24 | }; 25 | export default createReducer; 26 | 27 | -------------------------------------------------------------------------------- /packages/restaf/src/reducers/injectAsyncReducers.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | 19 | import createReducer from './createReducer'; 20 | // https://stackoverflow.com/questions/32968016/how-to-dynamically-load-reducers-for-code-splitting-in-a-redux-application/33044701#33044701 21 | const injectAsyncReducers = function ( store, name, asyncReducer ) { 22 | 23 | if ( store.asyncReducers.hasOwnProperty( name ) ) { 24 | delete store.asyncReducers[ name ]; 25 | } 26 | 27 | store.asyncReducers[ name ] = asyncReducer; 28 | 29 | store.replaceReducer( createReducer( store.asyncReducers ) ); 30 | 31 | }; 32 | 33 | export default injectAsyncReducers; -------------------------------------------------------------------------------- /packages/restaf/src/sagas/apiCall.js: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------------ 2 | Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software 9 | distributed under the License is distributed on an "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | See the License for the specific language governing permissions and 12 | 13 | limitations under the License. 14 | ---------------------------------------------------------------------------------------*/ 15 | 16 | 'use strict'; 17 | 18 | import { delay } from 'redux-saga/effects'; 19 | import { put, call, select} from 'redux-saga/effects'; 20 | 21 | import httpCall from './httpCall' ; 22 | import selectLogonInfo from '../store/selectLogonInfo'; 23 | 24 | function *apiCall ( action ) { 25 | let config = { ...action } ; 26 | 27 | config.logonInfo = yield select( selectLogonInfo ); 28 | yield put( { type: config.serviceName + '_' + action.type + '_BEGIN', config: config } ); 29 | 30 | if ( action.delay > 0 ) { 31 | yield delay ( action.delay * 1000 ); 32 | } 33 | 34 | let payload = yield call( httpCall, config ); 35 | 36 | yield put( payload ); 37 | 38 | } 39 | export default apiCall; -------------------------------------------------------------------------------- /packages/restaf/src/sagas/apiCallAction.js: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------------ 2 | Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software 9 | distributed under the License is distributed on an "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | See the License for the specific language governing permissions and 12 | limitations under the License. 13 | ---------------------------------------------------------------------------------------*/ 14 | 15 | 'use strict'; 16 | 17 | import { takeEvery } from 'redux-saga/effects' ; 18 | 19 | import { ADD_SERVICE, API_CALL } from '../actionTypes'; 20 | import apiCall from './apiCall'; 21 | 22 | function* apiCallAction () { 23 | yield takeEvery( [ ADD_SERVICE, API_CALL ] , apiCall ); 24 | } 25 | 26 | export default apiCallAction ; -------------------------------------------------------------------------------- /packages/restaf/src/sagas/apiPoll.js: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------------ 2 | Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software 9 | distributed under the License is distributed on an "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | See the License for the specific language governing permissions and 12 | limitations under the License. 13 | ---------------------------------------------------------------------------------------*/ 14 | 'use strict'; 15 | 16 | import {delay} from 'redux-saga/effects'; 17 | import {put, call, select} from 'redux-saga/effects'; 18 | 19 | import httpCallWait from './httpCallWait' ; 20 | import selectLogonInfo from '../store/selectLogonInfo'; 21 | 22 | function *apiPoll ( action ) { 23 | let config = {...action}; 24 | let payload = null; 25 | config.logonInfo = yield select( selectLogonInfo ); 26 | yield put( {type: config.serviceName + '_' + action.type + '_BEGIN', config: config} ); 27 | 28 | do { 29 | payload = yield call( httpCallWait, config ); 30 | /* move delay after the first call */ 31 | if ( config.delay ) { 32 | yield delay( config.delay * 1000 ); 33 | } 34 | } while ( payload === null ); 35 | 36 | yield put( payload ); 37 | } 38 | 39 | export default apiPoll; -------------------------------------------------------------------------------- /packages/restaf/src/sagas/apiPollAction.js: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------------ 2 | Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software 9 | distributed under the License is distributed on an "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | See the License for the specific language governing permissions and 12 | limitations under the License. 13 | ---------------------------------------------------------------------------------------*/ 14 | 'use strict'; 15 | 16 | import { takeEvery } from 'redux-saga/effects' ; 17 | 18 | import { API_POLL } from '../actionTypes'; 19 | import apiPoll from './apiPoll'; 20 | 21 | function* apiPollAction () { 22 | yield takeEvery( [ API_POLL ] , apiPoll ); 23 | } 24 | 25 | export default apiPollAction ; -------------------------------------------------------------------------------- /packages/restaf/src/sagas/appDataAction.js: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------------ 2 | Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software 9 | distributed under the License is distributed on an "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | See the License for the specific language governing permissions and 12 | limitations under the License. 13 | ---------------------------------------------------------------------------------------*/ 14 | 'use strict'; 15 | 16 | import {takeEvery} from 'redux-saga/effects' ; 17 | import {APP_DATA_ROOT, APP_DATA, APP_DATA_SETSTATE} from '../actionTypes'; 18 | import {API_STATUS_ROOT, API_STATUS, API_STATUS_SETSTATE} from '../actionTypes'; 19 | import {API_XSRF_ROOT, API_XSRF, API_XSRF_SETSTATE} from '../actionTypes'; 20 | import {put} from 'redux-saga/effects'; 21 | 22 | function* apiDataAction () { 23 | yield takeEvery( [ APP_DATA, API_STATUS, API_XSRF ] , appData ); 24 | } 25 | 26 | function *appData ( action ) { 27 | let newType; 28 | 29 | switch( action.type ) { 30 | case APP_DATA: newType = APP_DATA_ROOT + '_' + APP_DATA_SETSTATE; break; 31 | case API_STATUS: newType = API_STATUS_ROOT + '_' + API_STATUS_SETSTATE; break; 32 | default: newType = API_XSRF_ROOT + '_' + API_XSRF_SETSTATE; break; 33 | } 34 | 35 | let config = { 36 | type : newType, 37 | payload: action 38 | }; 39 | yield put( config ); 40 | } 41 | 42 | export default apiDataAction ; -------------------------------------------------------------------------------- /packages/restaf/src/sagas/httpCall.js: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------------ 2 | Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software 9 | distributed under the License is distributed on an "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | See the License for the specific language governing permissions and 12 | limitations under the License. 13 | ---------------------------------------------------------------------------------------*/ 14 | 'use strict'; 15 | 16 | import { request } from '../serverCalls' ; 17 | 18 | function httpCall ( config ) { 19 | if ( config.logonInfo === null ) { 20 | return httpDone( { error: 'Please logon' }, config, true ); 21 | } else { 22 | return ( request( config ) 23 | .then( response => httpDone( response, config, false ) ) 24 | .catch( error => httpDone( error, config, true ) ) 25 | ); 26 | } 27 | } 28 | function httpDone ( payload, config, error ) { 29 | return { 30 | error : error, 31 | type : config.serviceName + '_' + config.type + '_COMPLETE', 32 | config: config, 33 | payload 34 | }; 35 | } 36 | 37 | export default httpCall; -------------------------------------------------------------------------------- /packages/restaf/src/sagas/keepAliveAction.js: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------------ 2 | Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software 9 | distributed under the License is distributed on an "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | See the License for the specific language governing permissions and 12 | limitations under the License. 13 | ---------------------------------------------------------------------------------------*/ 14 | 'use strict'; 15 | 16 | import {takeLatest, spawn } from 'redux-saga/effects' ; 17 | import {KEEP_ALIVE} from '../actionTypes'; 18 | import {SASLogonOauthLink} from '../utils'; 19 | 20 | 21 | function* keepAliveAction () { 22 | 23 | let action = yield takeLatest( KEEP_ALIVE, keepAlivei ); 24 | //ignore results for now - not sure what the corrective action is if this fails 25 | // yield put({ type: KEEP_ALIVE});); 26 | } 27 | 28 | function* keepAlivei ( payload ){ 29 | let r = yield spawn ( test, payload ); 30 | return r; 31 | } 32 | 33 | function test ( action ){ 34 | let t = SASLogonOauthLink( 'keepAlive' ); 35 | return t.keepAlive( action ); 36 | } 37 | 38 | 39 | export default keepAliveAction ; -------------------------------------------------------------------------------- /packages/restaf/src/sagas/rafObjectAction.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved * * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * * you may not use this file except in compliance with the License. 5 | * * You may obtain a copy of the License at 6 | * * 7 | * * http://www.apache.org/licenses/LICENSE-2.0 8 | * * 9 | * * Unless required by applicable law or agreed to in writing, software 10 | * * distributed under the License is distributed on an "AS IS" BASIS, 11 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * ---------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 'use strict'; 18 | 19 | import {takeEvery} from 'redux-saga/effects' ; 20 | import {DELETE_RAF_OBJECT} from '../actionTypes'; 21 | import {put} from 'redux-saga/effects'; 22 | 23 | function* apiDataAction () { 24 | yield takeEvery( [ DELETE_RAF_OBJECT ] , rafObject ); 25 | } 26 | 27 | function *rafObject ( action ) { 28 | 29 | let config = { 30 | type : DELETE_RAF_OBJECT, 31 | payload: action 32 | }; 33 | yield put( config ); 34 | } 35 | 36 | export default apiDataAction ; -------------------------------------------------------------------------------- /packages/restaf/src/sagas/rootSaga.js: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------------ 2 | Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software 9 | distributed under the License is distributed on an "AS IS" BASIS, 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | See the License for the specific language governing permissions and 12 | limitations under the License. 13 | ---------------------------------------------------------------------------------------*/ 14 | 15 | 'use strict'; 16 | 17 | import { all } from 'redux-saga/effects'; 18 | import logonAction from './logonAction'; 19 | import apiCallAction from './apiCallAction'; 20 | import apiCallAllAction from './apiCallAllAction'; 21 | import apiPollAction from './apiPollAction'; 22 | import appDataAction from './appDataAction'; 23 | import keepAliveAction from './keepAliveAction'; 24 | 25 | 26 | function* rootSaga () { 27 | yield all ( [ 28 | logonAction(), 29 | apiCallAction(), 30 | apiCallAllAction(), 31 | apiPollAction(), 32 | appDataAction(), 33 | keepAliveAction() 34 | ] ); 35 | } 36 | export default rootSaga; -------------------------------------------------------------------------------- /packages/restaf/src/serverCalls/casSessionLinks.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | module.exports = function casSessionLinks ( uri, urihttp, casHttp, server, casProxyFlag ){ 7 | let href = ( casProxyFlag === true ) ? `${uri}/actions` : `${urihttp}/actions`; 8 | let isIdle = casProxyFlag === true ? `${uri}/isIdle` : `${urihttp}/isIdle`; 9 | let r = [ 10 | { 11 | method : 'POST', 12 | href : href, 13 | rel : 'execute', 14 | uri : href, 15 | responseType : 'application/json', 16 | type : 'application/json', 17 | itemType : 'application/json', 18 | title : 'Run CAS Action', 19 | customHandling: 'casExecute', 20 | casHttp : casHttp, 21 | server : server, 22 | extended : true 23 | }, 24 | 25 | { 26 | method : 'GET', 27 | href : isIdle, 28 | rel : 'state', 29 | uri : isIdle, 30 | responseType : 'application/json', 31 | type : 'application/json', 32 | itemType : 'application/json', 33 | title : 'state', 34 | customHandling: 'casState', 35 | casHttp : casHttp, 36 | server : server, 37 | extended : true 38 | } 39 | ]; 40 | 41 | return r; 42 | }; 43 | -------------------------------------------------------------------------------- /packages/restaf/src/serverCalls/fixImages.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | module.exports = function fixImages ( response ) { 7 | if ( response.data.results.hasOwnProperty( "images" ) === true ) { 8 | let images = response.data.results.images; 9 | let items = 10 | Array.isArray( images ) === true 11 | ? [].concat( images ) 12 | : Object.assign( {}, images ); 13 | items[0].id = "image"; 14 | response.data.results.items = items; 15 | delete response.data.results.images; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /packages/restaf/src/serverCalls/fixReports.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | module.exports = function fixReports ( response ) { 7 | let items = response.data.results.items; 8 | for ( let i = 0; i < items.length; i++ ) { 9 | let reportUri = `/SASReportViewer/?reportUri=/reports/reports/${ 10 | items[i].id 11 | }`; 12 | let l = { 13 | method : "GET", 14 | href : reportUri, 15 | rel : "viewer", 16 | uri : reportUri, 17 | type : "text/html", 18 | itemType: "text/html", 19 | title : "Report Viewer", 20 | extended: true 21 | }; 22 | 23 | items[i].links.push( l ); 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /packages/restaf/src/serverCalls/reduceCasResults.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | module.exports = function reduceCasResult ( data ) { 7 | let tables = {}; 8 | let tableByName = {}; 9 | if ( data.hasOwnProperty( "results" ) === false ) { 10 | return data; 11 | } 12 | for ( let k in data.results ) { 13 | //noinspection JSUnfilteredForInLoop 14 | let o = data.results[k]; 15 | if ( o.hasOwnProperty( "_ctb" ) === true && o["_ctb"] === true ) { 16 | //noinspection JSUnfilteredForInLoop 17 | tables[k] = o; 18 | tableByName[o.name] = o; 19 | } 20 | } 21 | data.tables = tables; /* need to deprecate this */ 22 | data.tablesByName = tableByName; 23 | return data; 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /packages/restaf/src/store/apiCall.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 'use strict'; 17 | 18 | import iapiCall from './iapiCall'; 19 | 20 | import { API_CALL, API_XSRF, API } from '../actionTypes'; 21 | import appData from './appData'; 22 | import readXsrfData from './readXsrfData'; 23 | import getXsrfData from './getXsrfData'; 24 | 25 | /** 26 | * @description make an api call to viya 27 | * @module apiCall 28 | * @category restaf/core 29 | * @param {rafLinkeRel} iroute 30 | * @param {*} payload 31 | * @param {...any} rest 32 | * @returns {promise} returns a rafObject 33 | */ 34 | async function apiCall ( store, iroute, payload, ...rest ) { 35 | // const apiCall = ( store, iroute, payload, ...rest ) => { 36 | 37 | let response = await iapiCall( store, iroute, API_CALL, payload, ...rest ); 38 | 39 | let newXsrf = readXsrfData(response.headers, response.usedService, iroute.route); 40 | if (newXsrf['x-csrf-header'] != null || newXsrf['tkhttp-id'] != null) { 41 | appData( store, API_XSRF, response.usedService, newXsrf); 42 | } 43 | if (newXsrf['tkhttp-id'] != null) { 44 | appData( store, API_XSRF, 'tkhttpid', newXsrf); 45 | } 46 | 47 | return response; 48 | }; 49 | 50 | export default apiCall; -------------------------------------------------------------------------------- /packages/restaf/src/store/appData.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | 19 | 20 | // import {APP_DATA} from '../actionTypes'; 21 | 22 | function appData ( store, type, route, payload ) { 23 | let action = { 24 | type : type, 25 | route: route, 26 | payload 27 | }; 28 | store.dispatch( action ); 29 | } 30 | 31 | export default appData; -------------------------------------------------------------------------------- /packages/restaf/src/store/configureSagaStore.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | import { createStore, applyMiddleware, compose } from 'redux'; 18 | import createSagaMiddleware from 'redux-saga'; 19 | import rootSaga from '../sagas/rootSaga'; 20 | import injectAsyncReducers from '../reducers/injectAsyncReducers'; 21 | 22 | 23 | import createReducer from '../reducers/createReducer'; 24 | 25 | function configureSagaStore ( config ) { 26 | 27 | let sagaMiddleWare = createSagaMiddleware(); 28 | 29 | // get default reducers 30 | let reducers = createReducer(); 31 | 32 | let store = createStore( reducers, 33 | applyMiddleware( sagaMiddleWare ) ); 34 | 35 | 36 | store.asyncReducers = {}; 37 | store.injectAsyncReducers = injectAsyncReducers; 38 | store.apiCallNo = 0; 39 | store.config = {...config}; 40 | 41 | // start the sagas 42 | 43 | sagaMiddleWare.run( rootSaga ) ; 44 | return store; 45 | } 46 | export default configureSagaStore; 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /packages/restaf/src/store/deleteRafObject.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved * * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * * you may not use this file except in compliance with the License. 5 | * * You may obtain a copy of the License at 6 | * * 7 | * * http://www.apache.org/licenses/LICENSE-2.0 8 | * * 9 | * * Unless required by applicable law or agreed to in writing, software 10 | * * distributed under the License is distributed on an "AS IS" BASIS, 11 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * ---------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 'use strict'; 18 | import {DELETE_RAF_OBJECT} from '../actionTypes'; 19 | import Immutable from 'immutable'; 20 | 21 | function deleteRafObject ( store, iroute ) { 22 | let route = null; 23 | if ( typeof iroute === 'string' ) { 24 | route = iroute; 25 | } else if ( Immutable.Iterable.isIterable( iroute ) === true ) { 26 | route = iroute.get( 'route' ); 27 | } 28 | 29 | if ( iroute !== null ) { 30 | let action = { 31 | type : DELETE_RAF_OBJECT, 32 | route: route 33 | }; 34 | store.dispatch( action ); 35 | } 36 | } 37 | 38 | export default deleteRafObject; -------------------------------------------------------------------------------- /packages/restaf/src/store/endStore.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | import {END} from "redux-saga"; 19 | const endStore = ( store ) => { 20 | store.dispatch( END ); 21 | }; 22 | export default endStore; -------------------------------------------------------------------------------- /packages/restaf/src/store/getResults.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 18 | import iGetResults from './iGetResults'; 19 | 20 | function getResults ( store, iroute, path ) { 21 | 22 | if ( path != undefined ) { 23 | return iGetResults( store, iroute, false, path ); 24 | } else { 25 | return iGetResults( store, iroute ); 26 | } 27 | } 28 | export default getResults; 29 | -------------------------------------------------------------------------------- /packages/restaf/src/store/getResults2.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | 19 | import iGetResults from './iGetResults'; 20 | 21 | function getResults2 ( store, iroute, prePath, ...args ) { 22 | 23 | let iquery = null; 24 | 25 | if ( args != null && args.length > 0 ) { 26 | iquery = ( Array.isArray( args [ 0 ] ) === true ) ? args[ 0 ] : args ; 27 | if ( prePath !== null ) { 28 | iquery = prePath.concat( iquery ); 29 | } 30 | } else { 31 | iquery = prePath; 32 | } 33 | 34 | 35 | return iGetResults( store, iroute, false, iquery ); 36 | 37 | } 38 | export default getResults2; 39 | -------------------------------------------------------------------------------- /packages/restaf/src/store/getServiceRoot.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | import extendFolder from './extendFolder'; 19 | 20 | function getServiceRoot ( store, serviceName ){ 21 | let f = null; 22 | let list = store.getState(); 23 | for ( let key in list ) { 24 | if ( key === serviceName ) { 25 | //noinspection JSUnfilteredForInLoop 26 | return extendFolder( store, list[ key] ); 27 | } 28 | } 29 | return f ; 30 | } 31 | export default getServiceRoot; -------------------------------------------------------------------------------- /packages/restaf/src/store/getServices.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | 19 | function getServices ( store ) { 20 | let list = store.getState(); 21 | let services = []; 22 | for ( let key in list ) { 23 | if ( key !== 'connections' ) { 24 | //noinspection JSUnfilteredForInLoop 25 | services.push( key ); 26 | } 27 | } 28 | return services; 29 | } 30 | export default getServices; -------------------------------------------------------------------------------- /packages/restaf/src/store/getXsrfData.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 'use strict'; 17 | 18 | import {API_XSRF_ROOT} from '../actionTypes'; 19 | function getXsrfData ( store, ...args ){ 20 | let list = store.getState(); 21 | list = list[API_XSRF_ROOT]; 22 | 23 | let path = ( args.length > 0 ) ? [ 'userData' ].concat( args ) : [ 'userData' ]; 24 | let xsrf = list.getIn( path, null ); 25 | 26 | return( xsrf != null ) ? xsrf.toJS() : null; 27 | } 28 | 29 | export default getXsrfData; 30 | -------------------------------------------------------------------------------- /packages/restaf/src/store/ikeepAlive.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | 19 | 20 | import {KEEP_ALIVE} from '../actionTypes'; 21 | import selectLogonInfo from './selectLogonInfo'; 22 | 23 | function ikeepAlive ( store ) { 24 | let logonInfo = selectLogonInfo( store.getState() ); 25 | if ( logonInfo.keepAlive != null ) { 26 | let action = { 27 | type : KEEP_ALIVE, 28 | route : 'keepAlive', 29 | payload: logonInfo 30 | }; 31 | store.dispatch( action ); 32 | } 33 | } 34 | 35 | export default ikeepAlive; -------------------------------------------------------------------------------- /packages/restaf/src/store/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | 19 | import initStore from './initStore'; 20 | import endStore from './endStore'; 21 | import restoreStore from './restoreStore'; 22 | 23 | export { 24 | initStore, 25 | endStore, 26 | restoreStore 27 | }; -------------------------------------------------------------------------------- /packages/restaf/src/store/logoff.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | 19 | let unSubscribe; 20 | import { VIYA_LOGOFF } from '../actionTypes'; 21 | /** 22 | * @description Logoff from Viya 23 | * @module logoff 24 | * @category restaf/core 25 | * @returns {promise} - result of logoff 26 | * @example 27 | * let r = await store.logoff(); 28 | */ 29 | function logoff ( store ) { 30 | //noinspection JSUnusedLocalSymbols 31 | return new Promise( ( resolve, reject ) => { 32 | let action = { 33 | type : VIYA_LOGOFF, 34 | storeConfig: store.config, 35 | payload : {} 36 | }; 37 | let logoffExit = () => { 38 | let newState = store.getState().connections; 39 | let runStatus = newState.get( 'runStatus' ); 40 | if ( runStatus === 'idle' ) { 41 | unSubscribe(); 42 | resolve( runStatus ); 43 | } else if ( runStatus === 'error' ) { 44 | unSubscribe(); 45 | reject( newState.get( 'statusInfo' ).toJS() ); 46 | } 47 | }; 48 | 49 | unSubscribe = store.subscribe( logoffExit ); 50 | store.dispatch( action ); 51 | 52 | } ); 53 | } 54 | export default logoff; -------------------------------------------------------------------------------- /packages/restaf/src/store/readXsrfData.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | function readXsrfData(headers, service, iroute) { 17 | let xsrfData = { 18 | serviceName: service, 19 | iroute: iroute, 20 | 'x-csrf-header': null, 21 | 'tkhttp-id': null 22 | } 23 | let xheader = headers( 'x-csrf-header' ) 24 | xsrfData['x-csrf-header'] = xheader; 25 | // xsrf data is present 26 | if (xheader != null) { 27 | xsrfData[xheader] = headers( xheader.toLowerCase() ); 28 | } 29 | // save tkhtt-id for cas use 30 | xsrfData['tkhttp-id'] = (headers('tkhttp-id') != null) ? headers('tkhttp-id') : null; 31 | return xsrfData; 32 | } 33 | export default readXsrfData; -------------------------------------------------------------------------------- /packages/restaf/src/store/request.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights reserved * * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * * you may not use this file except in compliance with the License. 5 | * * You may obtain a copy of the License at 6 | * * 7 | * * http://www.apache.org/licenses/LICENSE-2.0 8 | * * 9 | * * Unless required by applicable law or agreed to in writing, software 10 | * * distributed under the License is distributed on an "AS IS" BASIS, 11 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * ---------------------------------------------------------------------------------------- 15 | * 16 | */ 17 | 18 | 'use strict'; 19 | 20 | import axios from 'axios'; 21 | import Https from 'https'; 22 | async function request ( store, payload, reducer ) { 23 | 24 | let config = {...payload}; 25 | 26 | if ( payload.url.indexOf( 'https' ) !== -1 ) { 27 | let c = store.config; 28 | let opt = {}; 29 | if ( c.sslOptions != null ) { 30 | opt = c.sslOptions; 31 | } 32 | let agent = new Https.Agent( opt ); 33 | config.httpsAgent = agent; 34 | } 35 | let r = await axios( config ); 36 | return ( reducer == null ) ? r : reducer( r ); 37 | } 38 | 39 | export default request; -------------------------------------------------------------------------------- /packages/restaf/src/store/routeToObj.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | 19 | import extendFolder from './extendFolder' ; 20 | 21 | function routeToObj ( store, route ) { 22 | let path = route.split( ':/' ); 23 | let service = path.shift(); 24 | let folder = store.getState()[ service ]; 25 | folder = ( path.length > 0 ) ? folder.getIn( path ) : folder; 26 | return extendFolder( store, folder ); 27 | } 28 | 29 | export default routeToObj; -------------------------------------------------------------------------------- /packages/restaf/src/store/selectLogonInfo.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | 19 | export default function selectLogonInfo ( mainState ) { 20 | let state = mainState.connections ; 21 | let currentNo = state.get( 'currentConnection' ); 22 | return ( currentNo === -1 ) ? null : state.get( 'connections' ).get( currentNo ).toJS().logonInfo ; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /packages/restaf/src/store/xsrfData.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | 19 | 20 | import {API_XSRF} from '../actionTypes'; 21 | 22 | function xsrfData ( store, route, payload ) { 23 | let action = { 24 | type : API_XSRF, 25 | route: route, 26 | payload 27 | }; 28 | store.dispatch( action ); 29 | 30 | } 31 | 32 | export default xsrfData; -------------------------------------------------------------------------------- /packages/restaf/src/utils/SASLogoffOauthLink.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | 19 | import { request } from '../serverCalls' ; 20 | 21 | const SASLogoffOauthLink = function () { 22 | return ( 23 | { 24 | logoff: request, 25 | link : { 26 | href : '/SASLogon/logout', 27 | method : 'GET', 28 | rel : 'logoff', 29 | responseType: 'application/json', 30 | uri : '/SASLogon/logout' 31 | } 32 | } ); 33 | 34 | }; 35 | /* 36 | * redirectUri not specified - /SASLogon/oauth/token? 37 | */ 38 | export default SASLogoffOauthLink; 39 | -------------------------------------------------------------------------------- /packages/restaf/src/utils/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | 19 | import { setGoodStatus, setBadStatus } from './statusFuncs'; 20 | import SASLogonOauthLink from './SASLogonOauthLink'; 21 | import SASLogoffOauthLink from './SASLogoffOauthLink'; 22 | import routeOrFolder from './routeOrFolder'; 23 | import { tLinkStruct, itemsStruct, statusInfoStruct } from './rootStruct'; 24 | 25 | export { 26 | setGoodStatus, 27 | setBadStatus, 28 | SASLogonOauthLink, 29 | SASLogoffOauthLink, 30 | statusInfoStruct, 31 | tLinkStruct, 32 | itemsStruct, 33 | routeOrFolder 34 | }; 35 | -------------------------------------------------------------------------------- /packages/restaf/src/utils/routeOrFolder.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | 19 | let Immutable = require( 'immutable' ); 20 | 21 | function routeOrFolder ( iroute ){ 22 | let route = null; 23 | if ( typeof iroute === 'string' ) { 24 | route = iroute; 25 | } else { 26 | if ( Immutable.Iterable.isIterable( iroute ) === true ) { 27 | route = iroute.get( 'route', null ); 28 | } 29 | } 30 | return route; 31 | } 32 | export default routeOrFolder; -------------------------------------------------------------------------------- /packages/restaf/src/utils/statusFuncs.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | 19 | exports.setGoodStatus = function ( payload ) { 20 | return ( { 21 | status : payload.status, 22 | statusText: payload.statusText, 23 | detail : ' ', 24 | error : false 25 | } ); 26 | }; 27 | 28 | 29 | exports.setBadStatus = function ( payload ) { 30 | let code = 0 ; 31 | let detail = ' '; 32 | if ( payload.hasOwnProperty( 'response' ) && payload.response != null ) { 33 | code = payload.response.status; 34 | detail = ( payload.response.hasOwnProperty( 'data' ) ) ? payload.response.data : payload.response.statusText; 35 | } 36 | return ( { 37 | status : code, 38 | statusText: payload.message, 39 | detail : detail, 40 | error : true 41 | } ); 42 | 43 | }; 44 | -------------------------------------------------------------------------------- /packages/restaf/webpack.config.es.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = (env) => { 4 | const APP_PATH = path.resolve(__dirname, 'src'); 5 | const config = { 6 | context: APP_PATH, 7 | mode: 'production', 8 | optimization: { 9 | usedExports: true 10 | }, 11 | entry: [APP_PATH + '/index'], 12 | output: { 13 | path: path.join(__dirname, 'dist'), 14 | filename: 'index.esm.js', 15 | libraryTarget: 'module' // Use commonjs2 as a fallback 16 | }, 17 | module: { 18 | rules: [ 19 | { 20 | test: /\.js$/, 21 | exclude: /node_modules/, 22 | use: { 23 | loader: 'babel-loader', 24 | options: { 25 | presets: [ 26 | ['@babel/preset-env', { modules: false }] // Ensure Babel outputs ESM 27 | ] 28 | } 29 | } 30 | } 31 | ] 32 | } 33 | }; 34 | 35 | return config; 36 | }; -------------------------------------------------------------------------------- /packages/restaflib/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env" 4 | ], 5 | "plugins": [ 6 | "@babel/plugin-transform-regenerator", 7 | "@babel/plugin-transform-runtime", 8 | "@babel/plugin-syntax-dynamic-import", 9 | "@babel/plugin-syntax-import-meta", 10 | "@babel/plugin-proposal-class-properties", 11 | "@babel/plugin-proposal-json-strings", 12 | [ 13 | "@babel/plugin-proposal-decorators", 14 | { 15 | "legacy": true 16 | } 17 | ], 18 | "@babel/plugin-proposal-function-sent", 19 | "@babel/plugin-proposal-export-namespace-from", 20 | "@babel/plugin-proposal-numeric-separator", 21 | "@babel/plugin-proposal-throw-expressions", 22 | "@babel/plugin-proposal-export-default-from", 23 | "@babel/plugin-proposal-logical-assignment-operators", 24 | "@babel/plugin-proposal-optional-chaining", 25 | [ 26 | "@babel/plugin-proposal-pipeline-operator", 27 | { 28 | "proposal": "minimal" 29 | } 30 | ], 31 | "@babel/plugin-proposal-nullish-coalescing-operator", 32 | "@babel/plugin-proposal-do-expressions", 33 | "@babel/plugin-proposal-function-bind", 34 | "@babel/plugin-proposal-object-rest-spread" 35 | ] 36 | } -------------------------------------------------------------------------------- /packages/restaflib/jsdoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["plugins/markdown"], 3 | "recurseDepth": 10, 4 | "source": { 5 | "include": ["src"], 6 | "includePattern": ".js$|doc", 7 | "excludePattern": "(node_modules/|docs)" 8 | }, 9 | "templates": { 10 | "cleverLinks": true, 11 | "monospaceLinks": true 12 | }, 13 | "opts": { 14 | "destination": "../../docs/restaflib", 15 | "recurse": true, 16 | "readme": "./README.md" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/restaflib/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@sassoftware/restaflib", 3 | "version": "5.3.0-alpha.0", 4 | "description": "collection of useful functions for common scenarios", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/sassoftware/restaf/tree/master/packages/restaflib" 8 | }, 9 | "author": "Deva Kumar ", 10 | "license": "Apache-2.0", 11 | "engines": { 12 | "node": ">=10.16.0", 13 | "npm": ">=6.10.0" 14 | }, 15 | "browserslist": [ 16 | "last 2 versions", 17 | "ie >= 11", 18 | "maintained node versions" 19 | ], 20 | "unpkg": "/dist/restaflib.min.js", 21 | "main": "./lib/restaflib.js", 22 | "modules": "/dist/restaflib.min.js", 23 | "browser": "/dist/restaflib.min.js", 24 | "files": [ 25 | "lib", 26 | "dist" 27 | ], 28 | "bugs": { 29 | "url": "https://github.com/sassoftware/restaf/issues" 30 | }, 31 | "scripts": { 32 | "build": "rimraf dist && rimraf lib && webpack --env target=node p=n --config webpack.config.js && webpack --env target=web p=n --config webpack.config.js && webpack --env target=web p=y --config webpack.config.js", 33 | "pub": "npm publish --tag alpha --access public", 34 | "jsdoc": "jsdoc -c jsdoc.json", 35 | "dlink": "npm link", 36 | "bump": "npm version prerelease" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/restaflib/src/casActionRun.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | /** 7 | * 8 | * @description Calls cas server and returns the results(async) 9 | * 10 | * @async 11 | * @module casActionRun 12 | * @category restaflib/cas 13 | * @param {store} store - restaf store 14 | * @param {rafObject} session - cas session 15 | * @param {object} parameters - parameters for the action 16 | * 17 | * @returns {promise} returns results from cas 18 | * @alias module: casActionRun 19 | * @example 20 | * async function test_casAction () { 21 | * let {session} = await restaflib.casSetup(store); 22 | * // run fetch action 23 | * let p = 24 | * { action: 'table.fetch', 25 | * data : { table: { caslib: 'public', name: 'cars' } } 26 | * }; 27 | * let casResults = await restaflib.casActionRun(store, session, p); 28 | * print.object(casResults.tables.Fetch, 'Fetched Table'); 29 | * await store.apiCall(session.links('delete')); 30 | * } 31 | */ 32 | 'use strict'; 33 | 34 | 35 | // Notes: Function to call cas 36 | // See README file for notes on REUSECASSESSION 37 | // 38 | async function casActionRun ( store,...rest ) { 39 | let result = await store.runAction( ...rest ); 40 | return result.items().toJS(); 41 | } 42 | export default casActionRun; -------------------------------------------------------------------------------- /packages/restaflib/src/casAppendTable.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | import caslRunBase from './caslRunBase'; 7 | import casSaveTable from './casSaveTable'; 8 | import programs from './programs'; 9 | /** 10 | * @description Append a cas table to a master cas table 11 | * @async 12 | * @module casAppendTable 13 | * @category restaflib/cas 14 | * @param {store} store - store 15 | * @param {rafObject} session - cas session 16 | * @param {casTable} input Input table with new rows {caslib: xxx, name: nnn} 17 | * @param {casTable} output Master table {caslib: xxx, name: nnn} 18 | * @param {boolean} saveflag If true the master table will be saved to disk 19 | * @param {*} payload - 20 | * @returns {promise} - return 21 | * @example 22 | * let status = restaflib.casAppendTable(store, session, 'casuser.temp', 'public.master', true)); 23 | * 24 | */ 25 | async function casAppendTable ( store, session, input, output, save ){ 26 | let src = programs['commonCasl']() + ' ' + programs['casAppendTable'](); 27 | let args = { 28 | masterTable: output, 29 | setTable : input, 30 | save : ( save != null ) ? save : true 31 | }; 32 | let result = await caslRunBase( store, session, src, args ); 33 | let r = result.items( 'results', 'casResults' ).toJS(); 34 | 35 | if ( save === true ) { 36 | await casSaveTable( store, session, output ); 37 | } 38 | return r; 39 | } 40 | export default casAppendTable; 41 | -------------------------------------------------------------------------------- /packages/restaflib/src/casFetchData.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | import caslRunBase from './caslRunBase'; 7 | import programs from './programs'; 8 | /** 9 | * @description Fetch rows from cas Tables 10 | * @async 11 | * @module casFetchData 12 | * @category restaflib/cas 13 | * @param {store} store restaf store 14 | * @param {rafObject} session cas session 15 | * @param {object} payload info to read data 16 | * @returns {promise} returns data and data for scrolling. 17 | * @example 18 | * let payload = { start:0, limit:20, format: false, table: {caslib: 'casuser', name: 'sales'}} ; 19 | * let result = await casFetchData(store, session, payload); 20 | * result = { 21 | * data : {rows: array of row data, schema=}, 22 | * pagination: {next: {}, prev: {} 23 | * } 24 | * page = {start: , limit: , format: table: , name:} 25 | * } 26 | * Will return a row of length 0 if no data is found. 27 | * Will throw exceptions if cas code fails(ex: fetch action fails) 28 | */ 29 | async function casFetchData ( store, session, payload ){ 30 | let src = programs['commonCasl']() + ' ' + programs['casFetchData'](); 31 | // console.log(src); 32 | let result = await caslRunBase( store, session, src, payload ); 33 | 34 | return result.items( 'results', 'casResults' ).toJS(); 35 | } 36 | export default casFetchData; 37 | -------------------------------------------------------------------------------- /packages/restaflib/src/casLoadTable.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | 7 | import caslRun from './caslRun'; 8 | 9 | /** 10 | * 11 | * @description Save a cas table with replace by default 12 | * 13 | * @async 14 | * @module casLoadTable 15 | * @category restaflib/cas 16 | * @param {store} store restaf store 17 | * @param {session} session cas session 18 | * @param {casTable} table cas table to be loaded 19 | * 20 | * @returns {promise} returns status object 21 | */ 22 | async function casLoadTable ( store, session, table, _force ){ 23 | const src = ` 24 | print _args_; 25 | rc = checkAndLoadTable(_args_.caslib, _args_.name); 26 | if (rc ne true) then do; 27 | text = 'Unable to access ' ||_args_.caslib||'.'||_args_.name; 28 | rx = {severity=2,reason=6, status='error',statusCode=2, formatted=text}; 29 | exit(rx); 30 | end; 31 | print 'return code = ' || rc; 32 | send_response({casResults={status='ok'}}); 33 | `; 34 | 35 | const r = await caslRun( store,session, src, table, true ); 36 | return {msg: `${table.caslib}.${table.name} loaded}`, statusCode: 0}; 37 | } 38 | export default casLoadTable; -------------------------------------------------------------------------------- /packages/restaflib/src/casSaveTable.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | /** 7 | * 8 | * @description Save a cas table with replace by default 9 | * 10 | * @async 11 | * @module casSaveTable 12 | * @category restaflib/cas 13 | * @param {store} store restaf store 14 | * @param {session} session cas session 15 | * @param {casTable} table cas table to be saved 16 | * @param {boolean=} replace default is replace 17 | * @param {boolean=} loadTable load table (default= true) 18 | * 19 | * @returns {promise} returns status object 20 | */ 21 | async function casSaveTable ( store, session, table, replace, loadTable ){ 22 | const {caslib, name} = table; 23 | 24 | let payload = { 25 | action: 'table.save', 26 | data : { 27 | name : `${name}`, 28 | caslib : `${caslib}`, 29 | replace: ( replace === false ) ? false : true, 30 | table : table 31 | } 32 | }; 33 | await store.runAction( session, payload ); 34 | return {msg: `${caslib}.${name} saved}`, statusCode: 0}; 35 | } 36 | export default casSaveTable; -------------------------------------------------------------------------------- /packages/restaflib/src/casTableSummary.js: -------------------------------------------------------------------------------- 1 | 2 | import caslRunBase from './caslRunBase'; 3 | import programs from './programs'; 4 | 5 | /** 6 | * 7 | * @description Calls cas server and returns the results(async) 8 | * 9 | * @async 10 | * @module casTableSummary 11 | * @category restaflib/cas 12 | * 13 | * @param {store} store - restaf store 14 | * @param {casSession} session - cas session 15 | * @param {table} table - table 16 | * @returns {promise} returns results from cas 17 | * @example 18 | */ 19 | 20 | async function casTableSummary ( store, session, table ) { 21 | 22 | const src = ` 23 | action table.tableinfo r=result/ 24 | caslib= _args_.caslib name=_args_.name; 25 | run; 26 | summary = {rowcount = result.tableInfo[1, 'Rows'], 27 | columnCount=result.tableInfo[1, 'Columns'], 28 | source=result.tableInfo[1]}; 29 | `; 30 | 31 | let result = await caslRunBase( store, session,src, table, true ); 32 | 33 | return result.items().toJS(); 34 | } 35 | 36 | export default casTableSummary; -------------------------------------------------------------------------------- /packages/restaflib/src/casTableToJson.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | /** 7 | * @description Converts a cas table to JSON(utility) 8 | * @module casTableToJson 9 | * @category restaflib/util 10 | * @param {object} result - the raf object returned from a call to cas 11 | * @param {string} table - the name of the table 12 | * 13 | * @returns {object} - the new json version [{var1: value1, var2: value2,...}, {...}] 14 | * @alias module: casTableToJson 15 | * 16 | */ 17 | 18 | function casTableToJson ( result, table ){ 19 | let data = result.items( 'tables', table ); 20 | let itemRows = data.get( 'rows' ); 21 | let columns = []; 22 | data.get( 'schema' ).map( s => { 23 | columns.push( s.get( 'name' ) ); 24 | } ); 25 | 26 | let allResults = []; 27 | itemRows.map( ( r )=> { 28 | let row = {}; 29 | 30 | r.map( ( value, j ) => { 31 | row[columns[j]] = value; 32 | } ); 33 | allResults.push( row ); 34 | } ); 35 | return allResults; 36 | } 37 | 38 | export default casTableToJson; 39 | -------------------------------------------------------------------------------- /packages/restaflib/src/casUpload.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | 7 | import fs from 'fs'; 8 | 9 | import uploadSetup from './uploadSetup'; 10 | import { saveTable } from './uploadHandlers'; 11 | /** 12 | * @description upload different artifacts 13 | * @private 14 | * @async 15 | * @module casUpload 16 | * @param {store} store 17 | * @param {*} session 18 | * @param {*} source 19 | * @param {*} output 20 | * @param {*} save 21 | * @param {*} altSrc 22 | * @returns {promise} 23 | */ 24 | async function casUpload ( store, session, source, output,save, altSrc ){ 25 | // parse source file to figure out what we are uploading 26 | const fss = fs.promises 27 | let table = output; 28 | 29 | if ( typeof output === 'object' ) { 30 | table = `${output.caslib}.${output.name}`; 31 | } 32 | 33 | let fileInfo = uploadSetup( source, table ); 34 | // read the file 35 | 36 | let buf = ( altSrc != null ) ? altSrc : await fss.readFile( source, fileInfo.fileOptions ); 37 | 38 | // transfrom data if necessary for upload 39 | if ( fileInfo.transform !== null ) { 40 | buf = fileInfo.transform( buf, fileInfo ); 41 | } 42 | 43 | // upload using specific upload handlers 44 | 45 | let r = await fileInfo.handler( store, session, buf, fileInfo, save ); 46 | if ( save === true ) { 47 | let [ caslib, name ] = table.split( '.' ); 48 | await saveTable( store, session, caslib, name ); 49 | r = r + '\n' + ` ${output} was saved`; 50 | } 51 | return r; 52 | } 53 | export default casUpload; 54 | -------------------------------------------------------------------------------- /packages/restaflib/src/caslDescribe.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | /** 7 | * 8 | * @description Score data in casl 9 | * 10 | * @async 11 | * @module caslDescribe 12 | * @category restaflib/cas 13 | * @param {store} store - restaf store 14 | * @param {rafObject} session - cas session 15 | * @param {object} scenario - scenario values 16 | * 17 | * @returns {promise} returns the scores as an object 18 | */ 19 | 'use strict'; 20 | 21 | import caslRunBase from './caslRunBase'; 22 | import programs from './programs'; 23 | 24 | async function caslDescribe ( store, session, scenario ) { 25 | 26 | let src = programs['commonCasl']() + ' ' + programs['scoreCasl'](); 27 | let appEnv = {path: '/describe', ...scenario}; 28 | let result = await caslRunBase( store, session, src, appEnv ); 29 | let finalResult = result.items( 'results' ).toJS(); 30 | return finalResult; 31 | } 32 | export default caslDescribe; -------------------------------------------------------------------------------- /packages/restaflib/src/caslRunBase.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | import jsonToDict from './jsonToDict'; 7 | /** 8 | * lib 9 | */ 10 | /** 11 | * 12 | * @description Calls cas server and returns the results(async) 13 | * @private 14 | * @async 15 | * @function caslRunBase(async) 16 | * @category restaflib/cas 17 | * @param {object} store - restaf store 18 | * @param {object} session - cas session 19 | * @param {object} src - casl src statements 20 | * @param {object} args - arguments to pass to on to CAS as _args_ 21 | * 22 | * @returns {object} standard return value from apiCall 23 | */ 24 | async function caslRunBase ( store, session, src, args, ...rest ) { 25 | // 26 | // create casl statements for arguments and appenv 27 | // 28 | 29 | let _args_ = jsonToDict( ( args !== null ) ? args : {}, '_args_' ); 30 | 31 | let code = _args_ + ' ' + src; 32 | 33 | // Patch for issues with sccasl.runcasl via REST API 34 | 35 | code = code.replace( /\r?\n|\r/g, '' ); 36 | // setup payload for runAction 37 | let payload = { 38 | action: 'sccasl.runcasl', 39 | data : {code: code} 40 | }; 41 | 42 | let result = await store.runAction( session, payload, ...rest ); 43 | 44 | return result; 45 | } 46 | export default caslRunBase; -------------------------------------------------------------------------------- /packages/restaflib/src/caslScore.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | /** 6 | * lib 7 | */ 8 | /** 9 | * 10 | * @description Score data in casl 11 | * 12 | * @async 13 | * @module caslScore 14 | * @category restaflib/cas 15 | * @param {store} store - restaf store 16 | * @param {rafObject} session - cas session 17 | * @param {object} scenario - scenario values 18 | * 19 | * @returns {promise} returns the scores as an object 20 | */ 21 | 'use strict'; 22 | 23 | import caslRunBase from './caslRunBase'; 24 | import programs from './programs'; 25 | 26 | async function caslScore ( store, session, scenario ) { 27 | 28 | let src = programs['commonCasl']() + ' ' + programs['scoreCasl'](); 29 | let appEnv = {path: '/score', ...scenario}; 30 | let result = await caslRunBase( store, session, src, appEnv ); 31 | let finalResult = result.items( 'results', 'casResults' ).toJS()[0]; 32 | return finalResult; 33 | } 34 | export default caslScore; -------------------------------------------------------------------------------- /packages/restaflib/src/computeAppendTable.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | import computeRun from './computeRun'; 7 | 8 | /** 9 | * @description Append a compute table to a master compute table 10 | * @async 11 | * @module computeAppendTable 12 | * @category restaflib/compute 13 | * @param {store} store - store 14 | * @param {rafObject} session - compute session 15 | * @param {computeTable} input Input table with new rows {libref: xxx, name: nnn} 16 | * @param {computeTable} output Master table {computelib: xxx, name: nnn} 17 | * @returns {promise} - return 18 | * @example 19 | * let status = restaflib.computeAppendTable(store, session, 'computeuser.temp', 'public.master', true)); 20 | * 21 | */ 22 | async function computeAppendTable ( store, session, input, output ){ 23 | 24 | const src = ` 25 | proc append base=${output.libref}.{output.name} 26 | data= ${input.libref}.${input.name}; run; 27 | `; 28 | 29 | let computeSummary = await computeRun( store, session, src ); 30 | const statusCode = ( computeSummary.SASJobStatus === 'completed' ) ? 0 : 1; 31 | return {msg: `Append Completed. Status is: ${computeSummary.SASJobStatus}`, statusCode: statusCode }; 32 | } 33 | export default computeAppendTable; 34 | -------------------------------------------------------------------------------- /packages/restaflib/src/computeFileContent.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | // 7 | // Notes: Retrieve a SAS table and convert to a json 8 | // convert table to object of the form [{var1: value, var2: value,...},....] 9 | // ex: [{merlot:10, twobit:20}, {merlot: 20, twobit:30}] 10 | 11 | 'use strict'; 12 | /** 13 | * @description return content of a file output from a compute run 14 | * @async 15 | * @module computeFileContent 16 | * @category restaflib/compute 17 | * 18 | * @param {object} store - restaf store 19 | * @param {object} computeSummary - computeSummary 20 | * @param {string} fileref - name of the fileref 21 | * @param {boolean} url - set to true if you want the url and not the content 22 | * 23 | * @returns {promise} - get uri for content] 24 | */ 25 | async function computeFileContent ( store, computeSummary, fileref, url ) { 26 | 27 | let fileInfo = computeSummary.files[fileref]; 28 | if ( fileInfo == null ) { 29 | throw `Invalid fileref ${fileref}`; 30 | } 31 | if ( fileInfo.current === null ) { 32 | let payload = { 33 | qs: { 34 | filter: `eq(name,'${fileref}')` 35 | } 36 | }; 37 | let result = await store.apiCall( 38 | computeSummary.session.links( 'files' ), 39 | payload 40 | ); 41 | result = await store.apiCall( result.itemsCmd( fileref, 'self' ) ); 42 | fileInfo.current = result; 43 | } 44 | let r; 45 | if ( url === true ) { 46 | r = `${computeSummary.session.host}${fileInfo.current.links( 'content', 'link', 'uri' )}`; 47 | return r; 48 | } else { 49 | if ( fileInfo.data === null ) { 50 | let rx = await store.apiCall( fileInfo.current.links( 'content' ) ); 51 | let r = rx.items(); 52 | fileInfo.data = r; 53 | return r; 54 | } else { 55 | return fileInfo.data; 56 | } 57 | } 58 | 59 | } 60 | export default computeFileContent; 61 | -------------------------------------------------------------------------------- /packages/restaflib/src/computeResults.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | /** 6 | * @description Return Log|listing|ODS|list of tables in the compute service job 7 | * @async 8 | * @module computeResults 9 | * @category restaflib/compute 10 | * @param {object} store - restaf store 11 | * @param {object} computeSummary - computeSummary object 12 | * @param {string} type - type of result( log|listing|ods|table) 13 | * @returns {object|string} - string for all except table(array of names) 14 | */ 15 | async function computeResults ( store, computeSummary, type ) { 16 | if ( type === 'log' || type === 'listing' ) { 17 | let log = []; 18 | if ( computeSummary[type] !== null ) { 19 | let result = await store.apiCall( computeSummary[type] ); 20 | log = log.concat( result.items().toJS() ); 21 | let next; 22 | while ( ( next = result.scrollCmds( 'next' ) ) !== null ) { 23 | result = await store.apiCall( next ); 24 | log = log.concat( result.items().toJS() ); 25 | } 26 | } else { 27 | log[0] = `Note: No ${type}`; 28 | } 29 | return log; 30 | } else if ( type === 'ods' ) { 31 | if ( computeSummary.ods !== null ) { 32 | let result = await store.apiCall( computeSummary.ods ); 33 | return result.items(); 34 | } else { 35 | return '

No ODS output

'; 36 | } 37 | } else if ( type === 'tables' ) { 38 | return Object.keys( computeSummary.tables ); 39 | } else if ( type === 'files' ) { 40 | return Object.keys( computeSummary.files ); 41 | } else { 42 | throw `Error: Invalid type ${type}`; 43 | } 44 | } 45 | export default computeResults; 46 | -------------------------------------------------------------------------------- /packages/restaflib/src/computeRunBase.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | 7 | import computeSummary from './computeSummary'; 8 | /** 9 | * @description Reduce compute service execution results 10 | * @private 11 | * @async 12 | * @module computeRunBase 13 | * 14 | * @param {object} store - restaf store 15 | * @param {object} session - compute service session 16 | * @param {code} code - SAS code to be executed 17 | * @param {int} timeout optional - timeout for long poll in seconds(default= 5) 18 | 19 | * 20 | * @returns {object} computeSummary Object 21 | * 22 | */ 23 | 24 | async function computeRunBase ( store, session, code, timeout,eventHandler,userContext ){ 25 | 26 | let payload = { 27 | data: {code: code} 28 | }; 29 | // Now execute the data step and wait for completion 30 | 31 | // clear bad state if any 32 | 33 | let job = await store.apiCall( session.links( 'execute' ), payload ); 34 | 35 | let p = { 36 | qs: { 37 | wait: ( timeout != null ) ? timeout : 5 38 | }, 39 | headers: { 40 | "If-None-Match": job.headers( 'etag' ) 41 | } 42 | } 43 | let status = await store.jobState( job, p, 'longpoll', 0, eventHandler,userContext ); 44 | let results = await computeSummary( store, session, status.job ); 45 | results.SASJobStatus = status.data; 46 | results.jobStateStatus = status; 47 | return results; 48 | /* 49 | if ( status.data === 'running' ) { 50 | throw `ERROR: Job did not complete in allotted time`; 51 | } else { 52 | let results = await computeSummary( store, session, status.job ); 53 | results.SASJobStatus = status.data; 54 | results.jobStateStatus = status; 55 | return results; 56 | } 57 | */ 58 | } 59 | 60 | export default computeRunBase; 61 | -------------------------------------------------------------------------------- /packages/restaflib/src/computeSetupTables.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | 7 | import computeSummary from "./computeSummary"; 8 | import computeRun from './computeRun'; 9 | import computeResults from './computeResults'; 10 | 11 | /** 12 | * @description Setup access to compute service 13 | * @async 14 | * @private 15 | * @module computeSetup 16 | * @category restaflib/compute 17 | * 18 | * @param {store} store - restaf store 19 | * @param {session} SAS compute Session 20 | * @param {tables} tables Tables to be setup{libref:xx,name:xxx} or array of this object 21 | * @param {string} preamble SAS code to execute before setup 22 | * @returns {promise} - returns a compute summary 23 | */ 24 | async function computeSetupTables( store, session, tables, preamble ){ 25 | 26 | if ( preamble != null ) { 27 | const result = await computeRun( store, session, preamble ); 28 | if ( result.SASJobStatus !== 'completed' ) { 29 | throw `Error: Preamble failed with completion code of ${result.SASJobStatus}`; 30 | } 31 | 32 | } 33 | 34 | let r = await computeSummary( store, session, null, tables ); 35 | return r; 36 | } 37 | export default computeSetupTables; 38 | 39 | -------------------------------------------------------------------------------- /packages/restaflib/src/computeUpload.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | import computeRun from './computeRun'; 6 | /** 7 | * @description upload different artifacts 8 | * @private 9 | * @async 10 | * @module computeUpload 11 | * @param {store} store 12 | * @param {rafobject} session compute session 13 | * @param {computeTable} table - name of table to be created 14 | * @param {object} data - rows of data objects 15 | * @param {object} columns columns 16 | * @returns {promise} 17 | */ 18 | 19 | async function computeUpload ( store, session, table, csvArray, columns ){ 20 | let src = `data ${table.libref}.${table.name}; INFILE datalines delimiter=',' ;\n`; 21 | let l = ''; 22 | let inx = 'INPUT '; 23 | for ( const k in columns ) { 24 | const c = columns[k]; 25 | inx = inx + c.Column + ' '; 26 | if ( c.Type === 'CHAR' ) { 27 | const x = ` ${c.Column} $ ${c.length} \n`; 28 | l = l + ' ' + x; 29 | } 30 | } 31 | if ( l.length > 0 ) { 32 | l = 'LENGTH ' + l + ';\n'; 33 | } 34 | inx = inx + ';\n'; 35 | 36 | src = src + ';\n' + l + inx + 'datalines;\n' + csvArray + '\n; run; proc print;run;\n'; 37 | await computeRun( store, session, src ); 38 | return { msg: 'done', statusCode: 0 }; 39 | } 40 | 41 | export default computeUpload; 42 | -------------------------------------------------------------------------------- /packages/restaflib/src/findReport.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | 'use strict'; 7 | /** 8 | * @description Search for a named report(async) 9 | * @async 10 | * @module findReport 11 | * @category restaflib/report 12 | * 13 | * @param {object} store - restaf store 14 | * @param {string} name - name of the VA report (null to get a list of all reports) 15 | * 16 | * @returns {object} - either null or rafObject for the report 17 | */ 18 | 19 | async function findReport ( store, name ) { 20 | let reports = store.getService( 'reports' ); 21 | let payload = null; 22 | if ( name !== null ) { 23 | payload = { 24 | qs: { 25 | filter: `eq(name,'${name}')` 26 | } 27 | }; 28 | } 29 | // call the reports service 30 | 31 | let reportsList = await store.apiCall( reports.links( 'reports' ), payload ); 32 | // check to see if atleast one report was found(hopefully one only) 33 | return ( reportsList.itemsList().size === 0 ) ? null : reportsList; 34 | } 35 | export default findReport; 36 | 37 | -------------------------------------------------------------------------------- /packages/restaflib/src/getReportImage.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | /** 7 | * @description Return the svg of the specified report(async) 8 | * 9 | * @module getReportImage 10 | * @category restaflib/report 11 | * @param {object} store - restaf store 12 | * @param {string} name - name of the report 13 | * 14 | * @returns {string} - the svg of the report 15 | * 16 | */ 17 | import findReport from './findReport'; 18 | 19 | async function getReportImage ( store, name ) { 20 | let reportImages = store.rafObject( 'reportImages' ); 21 | 22 | let reportsList = await findReport( store, name ); 23 | if ( reportsList === null ) { 24 | return `${name} was not found`; 25 | } 26 | 27 | let uri = reportsList.itemsCmd( reportsList.itemsList( 0 ), 'self', 'link', 'uri' ); 28 | let data = { 29 | reportUri : uri, 30 | sectionIndex: 0, 31 | layoutType : 'entireSection', 32 | size : "400x400" 33 | }; 34 | 35 | let p = { data: data }; 36 | let job = await store.apiCall( reportImages.links( 'createJob' ), p ); 37 | let status = await store.jobState( job, { qs: { wait: 1.5} } , 10, 2 ); 38 | if ( status.data !== 'completed' ) { 39 | return `Job failed ${status.data}`; 40 | } 41 | let image = await store.apiCall( status.job.itemsCmd( status.job.itemsList( 0 ), 'image' ) ); 42 | 43 | return image.items(); 44 | 45 | } 46 | 47 | export default getReportImage; 48 | -------------------------------------------------------------------------------- /packages/restaflib/src/getReportUri.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | /** 7 | * @description Generate url for report(async) 8 | * @module getReportUri 9 | * @category restaflib/report 10 | * 11 | * @param {object} store - restaf store 12 | * @param {string} name - name of report 13 | * 14 | * @returns {promise} array of report's of the form {name: name, uri: uri} for the report(s) 15 | */ 16 | import findReport from './findReport'; 17 | async function getReportUri ( store, name ) { 18 | let reportsList = await findReport( store, name ); 19 | if ( reportsList === null ) { 20 | let e = ( name == null ) ? 'No reports were found' : `${name} was not found`; 21 | throw e; 22 | } 23 | let result = []; 24 | reportsList.items().map( ( i,n ) => { 25 | let uri = { 26 | name: n, 27 | uri : reportsList.itemsCmd( n, 'self', 'link', 'uri' ) 28 | }; 29 | result.push( uri ); 30 | } ); 31 | return result; 32 | } 33 | export default getReportUri; 34 | 35 | -------------------------------------------------------------------------------- /packages/restaflib/src/getSasTableRows.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | // 7 | // Notes: Retrieve a SAS table and convert to a json 8 | // convert table to object of the form [{var1: value, var2: value,...},....] 9 | // ex: [{merlot:10, twobit:20}, {merlot: 20, twobit:30}] 10 | 11 | 'use strict'; 12 | /** 13 | * @description Convert table to object of the form [{var1: value, var2: value,...},....](async) 14 | * @async 15 | * @private 16 | * @module getSASTableRows 17 | * @category restaflib/compute 18 | * 19 | * @param {object} store - restaf store 20 | * @param {object} computeSummary - computeSummary 21 | * @param {string} tableName - name of the table 22 | * 23 | * @returns {promise} - get retrieved rows [{var1:value, var2:...}] 24 | */ 25 | async function getSasTableRows ( store, computeSummary, tableName ){ 26 | 27 | let tableSelf = computeSummary.tables[tableName]; 28 | let t1 = await store.apiCall( tableSelf ); 29 | let table = await store.apiCall( t1.links( 'rowSet' ) ); 30 | 31 | let columns = table.items( 'columns' ); 32 | let rows = table.items( 'rows' ); 33 | let result = []; 34 | 35 | 36 | let count = rows.size; 37 | for ( let i=0; i < count; i++ ) { 38 | let row = rows.get( i ); 39 | let r = {}; 40 | columns.map( ( c,i ) => { 41 | let varx = c.toLowerCase(); 42 | r[varx] = row.get( i ); 43 | } ); 44 | result.push( r ); 45 | } 46 | return result; 47 | 48 | } 49 | export default getSasTableRows; 50 | -------------------------------------------------------------------------------- /packages/restaflib/src/getScoreStep.js: -------------------------------------------------------------------------------- 1 | import masAddModel from "@sassoftware/restaflib/src/masAddModel"; 2 | 3 | /* 4 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 5 | * SPDX-License-Identifier: Apache-2.0 6 | */ 7 | /** 8 | * @private 9 | * @module getScoreStep 10 | * @category restaflib/mas 11 | * @param {*} store 12 | * @param {*} microanalyticScore 13 | * @param {*} name 14 | * @returns {promise} 15 | */ 16 | async function getScoreStep ( store, microanalyticScore, name ) { 17 | 18 | let payload = { 19 | qs: { 20 | filter: `eq(name,'${name.trim()}')` 21 | } 22 | }; 23 | 24 | let modList = await store.apiCall( microanalyticScore.links( 'modules' ), payload ); 25 | // print.itemsList(modList, 'list of all models'); 26 | if ( modList.itemsList().size === 0 ) { 27 | return null; 28 | } 29 | 30 | let rafLink = modList.itemsCmd( name, 'steps' ); 31 | let allSteps = await store.apiCall( rafLink ); 32 | 33 | let control = { 34 | name : name, 35 | stepsRafLink : allSteps, 36 | stepIds : modList.items( name, 'data','stepIds' ).toJS(), 37 | microanalyticScore: microanalyticScore 38 | }; 39 | return control; 40 | 41 | } 42 | 43 | export default getScoreStep; 44 | -------------------------------------------------------------------------------- /packages/restaflib/src/jesRunBase.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | import jesSummary from './jesSummary'; 7 | // 8 | // Notes: Run compute service 9 | // 10 | /** 11 | * @description Reduce compute service to an consummable form(async) 12 | * @private 13 | * @module jesRunBase 14 | * 15 | * @param {object} sore - restaf store 16 | * @param {code} code - SAS code to be executed 17 | * 18 | * @returns {object} rafobject of the results from a sas compute job 19 | * 20 | */ 21 | 22 | async function jesRunBase ( store, jes, payload ){ 23 | let job = await store.apiCall( jes.links( 'create' ), payload ); 24 | let status = await store.jobState( job, null, 5, 2 ); 25 | 26 | if ( status.data === 'running' ) { 27 | throw `ERROR: Job did not complete in allotted time`; 28 | } else if ( status.data === 'failed' ) { 29 | throw JSON.stringify( status ); 30 | } else { 31 | let results = await jesSummary ( store, status.job ); 32 | return results; 33 | } 34 | } 35 | export default jesRunBase; 36 | 37 | -------------------------------------------------------------------------------- /packages/restaflib/src/jesSetup.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | /** 7 | * @description Setup access to compute service 8 | * @async 9 | * @module jesSetup 10 | * @private 11 | * 12 | * @param {object} store - restaf store 13 | * @param {object} payload - logon payload - If null assumes that logon was done earlier. 14 | * 15 | * @returns {object} - returns a jobExecution raf object 16 | */ 17 | async function jesSetup ( store, payload ){ 18 | if ( payload != null ) { 19 | await store.logon( payload ); 20 | } 21 | let services = await store.addServices( 'jobExecution', 'compute', 'jobDefinitions' ); 22 | return services.jobExecution; 23 | } 24 | export default jesSetup; 25 | 26 | -------------------------------------------------------------------------------- /packages/restaflib/src/jesSummary.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | /** 7 | * @description Reduce the job information into consummable form(async) 8 | * 9 | * @async 10 | * @module jesSummary 11 | * @category restaflib/jes 12 | * @private 13 | * @param {object} store - restaf store 14 | * @param {object} job - rafObject representing the compute service job 15 | * 16 | * @returns {object} - the computeSummary object for easy handling of logs,listing,ods, tables 17 | */ 18 | async function jesSummary ( store, job ){ 19 | 20 | return job; 21 | 22 | } 23 | export default jesSummary; 24 | 25 | -------------------------------------------------------------------------------- /packages/restaflib/src/masAddModel.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | /** 7 | * setup access to MAS 8 | * @module masSetup 9 | * @category restaflib/mas 10 | * @param {object} store - restaf store 11 | * @param {object} masControl - control object from masSetup 12 | * @param {object} models - array of models to add 13 | * 14 | * @returns {object} - masControl used in masRun 15 | * @alias module: masSetup 16 | * @example 17 | * let masControl = await masSetup(store, ['modelA', 'modelB']); 18 | */ 19 | import getScoreStep from './getScoreStep'; 20 | 21 | async function masAddModel ( store,masControl, models ){ 22 | let microanalyticScore = masControl.service; 23 | for ( let i=0; i < models.length; i++ ) { 24 | let m = models[ i ]; 25 | if ( masControl.steps[m] == null ) { 26 | let result = await getScoreStep( store, microanalyticScore, m ); 27 | masControl.steps[m] = result; 28 | } 29 | } 30 | return true; 31 | } 32 | 33 | 34 | 35 | export default masAddModel; -------------------------------------------------------------------------------- /packages/restaflib/src/masDescribe.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | /** 6 | * Score using MAS 7 | * @module masDescribe 8 | * @category restaflib/mas 9 | * @param {object} masControl - object from masSetup 10 | * @param {string} modelName - name of model to be executed 11 | * @param {string} step - if not specified it will try to find score or execute 12 | * 13 | * @returns {object} - return input information 14 | * @alias module: masDescribe 15 | * @example 16 | * let inputs = restaflib.masDescribe(masControl, 'modela', 'score'); 17 | */ 18 | function masDescribe ( masControl, modelName, step ) { 19 | let stepControl = masControl.steps[ modelName ]; 20 | if ( stepControl === null ) { 21 | return []; 22 | } 23 | let currentStep = null; 24 | if ( step == null ) { 25 | let stepIndex = stepControl.stepIds.findIndex( x => ( x === 'execute' ) ||( x === 'score' ) ); 26 | if ( stepIndex === -1 ) { 27 | return []; 28 | } else { 29 | currentStep = stepControl.stepIds[stepIndex]; 30 | } 31 | } else { 32 | let stepIndex = stepControl.stepIds.findIndex( x => ( x === step ) ); 33 | if ( stepIndex === -1 ) { 34 | return []; 35 | } else { 36 | currentStep = step; 37 | } 38 | } 39 | let desc = stepControl.stepsRafLink.items( currentStep, 'data', 'inputs' ); 40 | if ( desc === null ) { 41 | return []; 42 | } 43 | 44 | return desc.toJS(); 45 | } 46 | export default masDescribe; -------------------------------------------------------------------------------- /packages/restaflib/src/masScore.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | /** 6 | * Score using MAS 7 | * @module masScore 8 | * @category restaflib/mas 9 | * @param {store} restaf store 10 | * @param {string} modelName - name of model to be executed 11 | * @param {object} scenario - can be [{name: var1, value: value1},{...} ] or {varname: value,...} 12 | * @returns {promise} - returns scoring results 13 | * @alias module: masScore 14 | * @example 15 | * async function example (store, model) { 16 | * let scenario = { 17 | * prescriber_count : 1, 18 | * strength_per_unit: 15, 19 | * age : 74, 20 | * avg_opioid_prescriber_rate: 10.4, 21 | * doctorshop_med : 1, 22 | * max_avg_med_90 : 10, 23 | * max_mme_per_day: 40, 24 | * max_opioid_prescriber_rate: 13.21, 25 | * opioid_days: 3 26 | * }; 27 | * 28 | * let result = await restaflib.masScore (store, model, scenario); 29 | * print.object(result, 'scoring result'); 30 | * } 31 | */ 32 | import masSetup from './masSetup'; 33 | import masRun from './masRun'; 34 | 35 | async function masScore ( store, modelName, scenario ) { 36 | let masControl = await masSetup( store,[ modelName ] ); 37 | let r = await masRun( store,masControl, modelName, scenario, 'score', 'execute' ); 38 | return r; 39 | } 40 | export default masScore; -------------------------------------------------------------------------------- /packages/restaflib/src/masSetup.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | /** 7 | * setup access to MAS 8 | * @module masSetup 9 | * @category restaflib/mas 10 | * @param {object} store - restaf store 11 | * @param {object} models - an array of model names 12 | * @param {object} logonPayload - null|restaf logon payload 13 | * 14 | * @returns {object} - masControl used in masRun 15 | * @alias module: masSetup 16 | * @example 17 | * let masControl = await masSetup(store, ['modelA', 'modelB']); 18 | */ 19 | import getScoreStep from './getScoreStep'; 20 | async function masSetup ( store,models, logonPayload ){ 21 | if ( logonPayload != null ) { 22 | await store.logon( logonPayload ); 23 | } 24 | let { microanalyticScore } = await store.addServices( 'microanalyticScore' ); 25 | 26 | let control = { 27 | service: microanalyticScore, 28 | steps : {} 29 | } 30 | ; 31 | for ( let i=0; i < models.length; i++ ) { 32 | let m = models[ i ]; 33 | let result = await getScoreStep( store, microanalyticScore, m ); 34 | control.steps[ m ] = result; 35 | } 36 | 37 | return control; 38 | } 39 | 40 | export default masSetup; -------------------------------------------------------------------------------- /packages/restaflib/src/print/logListLines.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | // 7 | // Notes: Convert Loglines to html 8 | // 9 | 10 | /** 11 | * Return log lines as html(async) 12 | * @module logLines 13 | * @param {object} folder - raf Object for log lines 14 | * 15 | * @returns {string} log lines as HTML 16 | * 17 | */ 18 | import colors from 'colors'; 19 | 20 | async function logListLines ( dataL ) { 21 | 22 | dataL.map( ( data ) => { 23 | let line = data.line.replace( /(\r\n|\n|\r)/gm, "" ); 24 | if ( line.length === 0 ) { 25 | console.log( ' ' ); 26 | } 27 | let type = data.type; 28 | if ( type === 'title' ) { 29 | console.log( colors.bold( line ) ); 30 | } else { 31 | console.log( line ); 32 | } 33 | } ); 34 | return; 35 | } 36 | export default logListLines; -------------------------------------------------------------------------------- /packages/restaflib/src/programs/casAppendTable.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | function casAppendTable() { 7 | let src = ` 8 | rc = checkAndLoadTable(_args_.masterTable.caslib, _args_.masterTable.name); 9 | 10 | if (rc ne true) then do; 11 | text = 'Unable to access ' ||_args_.masterTable.caslib||'.'||_args_.masterTable.name; 12 | rx = {severity=2,reason=6, status='error',statusCode=2, formatted=text}; 13 | exit(rx); 14 | end; 15 | 16 | rc = checkAndLoadTable(_args_.setTable.caslib, _args_.setTable.name); 17 | if (rc ne true) then do; 18 | text = 'Unable to access ' ||_args_.setTable.caslib||'.'||_args_.setTable.name; 19 | rx = {severity=2,reason=6, status='error',statusCode=2, formatted=text}; 20 | return rx; 21 | end; 22 | 23 | 24 | setdata = _args_.setTable.caslib ||'.'||_args_.setTable.name; 25 | masterdata = _args_.masterTable.caslib ||'.'||_args_.masterTable.name; 26 | 27 | action datastep.runCode r=result status=rc/ 28 | code='data ' ||masterdata||'(append=YES);set ' || setdata ||'; run;'; 29 | 30 | if (rc.statusCode ne 0) then do; 31 | exit(rc); 32 | end; 33 | else do; 34 | results = {msg= 'Append succeeded', statusCode=true}; 35 | end; 36 | 37 | send_response({casResults = results}); 38 | `; 39 | return src; 40 | } 41 | export default casAppendTable; -------------------------------------------------------------------------------- /packages/restaflib/src/programs/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | import scoreCasl from './scoreCasl'; 7 | import casFetchData from './casFetchData'; 8 | import commonCasl from './commonCasl'; 9 | import casFetchRows from './casFetchRows'; 10 | import casAppendTable from './casAppendTable'; 11 | import casRowSets from './casFetchData'; 12 | 13 | export default {commonCasl, casFetchData, casFetchRows, scoreCasl, casAppendTable, casRowSets}; -------------------------------------------------------------------------------- /packages/restaflib/src/uploadHandlers/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | 7 | import uploadAstore from './uploadAstore'; 8 | import uploadSrc from './uploadSrc'; 9 | import saveTable from './saveTable'; 10 | 11 | export { 12 | uploadAstore, 13 | uploadSrc, 14 | saveTable 15 | }; -------------------------------------------------------------------------------- /packages/restaflib/src/uploadHandlers/saveTable.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | async function saveTable ( store, session, caslib, name ){ 7 | let payload = { 8 | action: 'table.save', 9 | data : { 10 | name : `${name}`, 11 | caslib : `${caslib}`, 12 | replace: true, 13 | table : { name: `${name}`, caslib: `${caslib}` } 14 | } 15 | }; 16 | 17 | await store.runAction( session, payload ); 18 | } 19 | export default saveTable; -------------------------------------------------------------------------------- /packages/restaflib/src/uploadHandlers/uploadAstore.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 'use strict'; 6 | 7 | async function uploadAstore ( store, session, astoreBuf, fileInfo ) { 8 | let { caslib, name } = fileInfo.output; 9 | if ( name == null ) { 10 | throw 'Please specify table as caslib.name'; 11 | } 12 | name = name.toLowerCase( name ); 13 | 14 | // delete old table 15 | let casl = ` 16 | action table.droptable / 17 | caslib= '${caslib}' name= '${name}' quiet=true; 18 | 19 | action table.deleteSource/ 20 | caslib= '${caslib}' source= '${name}.sashdat' quiet=true; 21 | `; 22 | 23 | let payload = { 24 | action: 'sccasl.runcasl', 25 | data : { code: casl } 26 | }; 27 | await store.runAction( session, payload ); 28 | 29 | // upload table 30 | 31 | payload = { 32 | action: 'astore.upload', 33 | data : { 34 | rstore: { name: `${name}`, caslib: `${caslib}`, replace: true }, 35 | store : astoreBuf 36 | } 37 | }; 38 | 39 | let r = await store.runAction( session, payload ); 40 | 41 | return `Upload of ${fileInfo.source} to ${caslib}.${name} completed`; 42 | } 43 | 44 | export default uploadAstore; 45 | -------------------------------------------------------------------------------- /packages/restaflib/webpack.config.es.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = (env) => { 4 | const APP_PATH = path.resolve(__dirname, 'src'); 5 | const config = { 6 | context: APP_PATH, 7 | mode: 'production', 8 | optimization: { 9 | usedExports: true 10 | }, 11 | entry: [APP_PATH + '/index'], 12 | output: { 13 | path: path.join(__dirname, 'dist'), 14 | filename: 'index.esm.js', 15 | libraryTarget: 'module' // Use commonjs2 as a fallback 16 | }, 17 | module: { 18 | rules: [ 19 | { 20 | test: /\.js$/, 21 | exclude: /node_modules/, 22 | use: { 23 | loader: 'babel-loader', 24 | options: { 25 | presets: [ 26 | ['@babel/preset-env', { modules: false }] // Ensure Babel outputs ESM 27 | ] 28 | } 29 | } 30 | } 31 | ] 32 | } 33 | }; 34 | 35 | return config; 36 | }; -------------------------------------------------------------------------------- /packages/tests/appData.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | /* 18 | * Testing Application Data Management (setAppData and getAppData) 19 | */ 20 | "use strict"; 21 | let restaf = require( "@sassoftware/restaf" ); 22 | let {casSetup} = require( "@sassoftware/restaflib" ); 23 | // let prtUtil = require("../prtUtil"); 24 | 25 | 26 | // Test appdata 27 | async function setup () { 28 | console.log( "Initial value" ); 29 | let store = restaf.initStore(); 30 | let d = store.getAppData(); 31 | console.log( d.toJS() ); 32 | 33 | store.setAppData( "aaa", { x: 1, y: 2 } ); 34 | d = store.getAppData(); 35 | console.log( d.toJS(), "After first set" ); 36 | 37 | store.setAppData( "bbb", { a: 1, b: 2 } ); 38 | d = store.getAppData(); 39 | console.log( d.toJS(), "After second set" ); 40 | 41 | d = store.getAppData( "bbb" ); 42 | console.log( d.toJS(), "Get specific set" ); 43 | 44 | d = store.getAppData( "bbb", "a" ); 45 | console.log( d, "Query for nested value" ); 46 | 47 | 48 | return "completed"; 49 | } 50 | 51 | setup() 52 | .then( r => console.log( r ) ) 53 | .catch( e => console.log( e ) ); -------------------------------------------------------------------------------- /packages/tests/cas.append.table.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | const testFunctions = require( '../examples/testFunctions/casAppendTable1.js' ); 19 | const setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'cas.append.table', async () => { 33 | let r = await testFunctions( testInfo, true ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/cas.basic.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | let testFunctions = require( '../examples/testFunctions/casEcho' ); 19 | let setupAll = require( '../examples/lib/setupAll' ); 20 | const casEcho = require('../examples/testFunctions/casEcho'); 21 | let testInfo; 22 | beforeAll( async () => { 23 | try { 24 | 25 | console.log( 'calling setup' ); 26 | testInfo = await setupAll(); 27 | } catch ( err ) { 28 | console.log( err ); 29 | process.exit( 1 ); 30 | } 31 | } ); 32 | test( 'CAS Echo', async () => { 33 | debugger; 34 | let r = await testFunctions( testInfo ); 35 | expect( r ).toBe( 'done' ); 36 | } ); 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/cas.ds.load.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | const testFunctions = require( '../examples/testFunctions/casDSLoad.js' ); 19 | const setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'cas.ds.load.test.js', async () => { 33 | let r = await testFunctions( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/cas.fetch.scroll.fail.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | const testFunctions = require( '../examples/testFunctions/casFetchScrollFail.js' ); 19 | const setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'cas.fetch.scroll.js', async () => { 33 | let r = await testFunctions( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/cas.fetch.scroll.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | const testFunctions = require( '../examples/testFunctions/casFetchScroll.js' ); 19 | const setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'cas.fetch.scroll.js', async () => { 33 | let r = await testFunctions( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/cas.fetch.scroll.where.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | const testFunctions = require( '../examples/testFunctions/casFetchScrollWhere.js' ); 19 | const setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'cas.fetch.scroll.js', async () => { 33 | let r = await testFunctions( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/cas.session.test.js: -------------------------------------------------------------------------------- 1 | let testFunctions = require( '../examples/testFunctions/casSession' ); 2 | let setupAll = require( '../examples/lib/setupAll' ); 3 | let testInfo; 4 | beforeAll( async () => { 5 | try { 6 | 7 | console.log( 'calling setup' ); 8 | testInfo = await setupAll(); 9 | } catch ( err ) { 10 | console.log( err ); 11 | process.exit( 1 ); 12 | } 13 | } ); 14 | 15 | test( 'CAS Session', async () => { 16 | let r = await testFunctions( testInfo ); 17 | expect( r ).toBe( 'done' ); 18 | } ); 19 | -------------------------------------------------------------------------------- /packages/tests/cas.submit.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | let testFunctions = require( '../examples/testFunctions/casSubmit' ); 19 | let setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'CAS Submit', async () => { 33 | let r = await testFunctions( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /packages/tests/cas.unique.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | let testFunctions = require( '../examples/testFunctions/casUnique.js' ); 19 | let setupAll = require( '../examples/lib/setupAll.js' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'CAS Unique', async () => { 33 | let r = await testFunctions( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/compute.attach.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | const testFunctions = require( '../examples/testFunctions/computeDSAttach.js' ); 19 | const setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'compute.attach', async () => { 33 | let r = await testFunctions( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/compute.basic.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | const testFunctions = require( '../examples/testFunctions/computeBasic.js' ); 19 | const setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'computeBasic', async () => { 33 | let r = await testFunctions( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/compute.fetch.scroll.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | const testFunctions = require( '../examples/testFunctions/computeFetchScroll.js' ); 19 | const setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'compute.fetch.scroll.js', async () => { 33 | let r = await testFunctions( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/compute.fetch.scroll.where.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | const testFunctions = require( '../examples/testFunctions/computeFetchScrollWhere.js' ); 19 | const setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'cas.fetch.scroll.js', async () => { 33 | let r = await testFunctions( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/compute.unique.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | const testFunctions = require( '../examples/testFunctions/computeDS.js' ); 19 | const setupAll = require( '../examples/lib/setupAll.js' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'cas.fetch.scroll.js', async () => { 33 | let r = await testFunctions( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/computeTable.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | const testFunctions = require( '../examples/testFunctions/computeTables.js' ); 19 | const setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'c.js', async () => { 33 | let r = await testFunctions( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/filesCreate.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | let testFunctions = require( '../examples/testFunctions/filesCreate.js' ); 19 | let setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | console.log( 'calling setup' ); 24 | testInfo = await setupAll(); 25 | } catch ( err ) { 26 | console.log( err ); 27 | process.exit( 1 ); 28 | } 29 | } ); 30 | 31 | test( 'filesCreate.js', async () => { 32 | let r = await testFunctions( testInfo ); 33 | expect( r ).toBe( 'done' ); 34 | } ); 35 | 36 | 37 | -------------------------------------------------------------------------------- /packages/tests/filesPaginate.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | let testFunctions = require( '../examples/testFunctions/filesPaginate.js' ); 19 | let setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | console.log( 'calling setup' ); 24 | testInfo = await setupAll(); 25 | } catch ( err ) { 26 | console.log( err ); 27 | process.exit( 1 ); 28 | } 29 | } ); 30 | 31 | test( 'filesPaginate.js', async () => { 32 | let r = await testFunctions( testInfo ); 33 | expect( r ).toBe( 'done' ); 34 | } ); 35 | 36 | 37 | -------------------------------------------------------------------------------- /packages/tests/foldersPaginate.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | let testFunctions = require( '../examples/testFunctions/foldersPaginate.js' ); 19 | let setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | console.log( 'calling setup' ); 24 | testInfo = await setupAll(); 25 | } catch ( err ) { 26 | console.log( err ); 27 | process.exit( 1 ); 28 | } 29 | } ); 30 | 31 | test( 'foldersPaginate.js', async () => { 32 | let r = await testFunctions( testInfo ); 33 | expect( r ).toBe( 'done' ); 34 | } ); 35 | 36 | 37 | -------------------------------------------------------------------------------- /packages/tests/maslist.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | let testFunctions = require( '../examples/testFunctions/masList.js' ); 19 | let setupAll = require( '../examples/lib/setupAll.js' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'MAS score', async () => { 33 | let r = await testFunctions( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/masscore.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | let testFunctions = require( '../examples/testFunctions/masScore.js' ); 19 | let setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | 24 | console.log( 'calling setup' ); 25 | testInfo = await setupAll(); 26 | } catch ( err ) { 27 | console.log( err ); 28 | process.exit( 1 ); 29 | } 30 | } ); 31 | 32 | test( 'MAS score', async () => { 33 | let r = await testFunctions( testInfo ); 34 | expect( r ).toBe( 'done' ); 35 | } ); 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/tests/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tests", 3 | "version": "5.3.0-alpha", 4 | "description": "Tests", 5 | "author": "Deva Kumaraswamy ", 6 | "license": "Apache-2.0", 7 | "keywords": [ 8 | "restaf", 9 | "SAS", 10 | "Viya", 11 | "REST API" 12 | ], 13 | "main": "index.js", 14 | "engines": { 15 | "node": ">=10.16.0", 16 | "npm": ">=6.10.0", 17 | "yarn": ">=1.17.3" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/sassoftware/restaf/tree/master/packages/examples" 22 | }, 23 | "bugs": { 24 | "url": "https://github.com/sassoftware/restaf/issues" 25 | }, 26 | "scripts": { 27 | "test": "cross-env RESTAFENV=.env NODE_TLS_REJECT_UNAUTHORIZED=0 npx jest", 28 | "debug": "cross-env RESTAFENV=.env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk ../../node_modules/jest/bin/jest.js --runInBand" 29 | }, 30 | "jest": { 31 | "testTimeout": 10000000, 32 | "verbose": false 33 | }, 34 | "dependencies": { 35 | "cross-env": "^7.0.3", 36 | "jest": "^27.5.0", 37 | "winston": "^3.2.1" 38 | }, 39 | "devDependencies": { 40 | "eslint": "^8.8.0", 41 | "microbundle": "^0.15.1" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/tests/parentURI.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------------------------------ 3 | * Copyright © 2023, SAS Institute Inc., Cary, NC, USA. * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * --------------------------------------------------------------------------------------- 14 | * 15 | */ 16 | 17 | 'use strict'; 18 | let testFunctions = require( '../examples/testFunctions/parentURI.js' ); 19 | let setupAll = require( '../examples/lib/setupAll' ); 20 | let testInfo; 21 | beforeAll( async () => { 22 | try { 23 | console.log( 'calling setup' ); 24 | testInfo = await setupAll(); 25 | } catch ( err ) { 26 | console.log( err ); 27 | process.exit( 1 ); 28 | } 29 | } ); 30 | 31 | test( 'parentURI.js', async () => { 32 | let r = await testFunctions( testInfo ); 33 | expect( r ).toBe( 'done' ); 34 | } ); 35 | 36 | 37 | -------------------------------------------------------------------------------- /packages/tests/restaf.basic.test.js: -------------------------------------------------------------------------------- 1 | let restaf = require( 'restaf' ); 2 | let getToken = require( './getToken' ); 3 | let logonPayload = { 4 | host : process.env.VIYA_SERVER, 5 | authType: 'server', 6 | token : getToken(), 7 | tokenTy 8 | } 9 | 10 | const store = restaf.initStore() 11 | let msg = store.logon( logonPayload ); 12 | console.log( msg ); 13 | let {casManagement, files} = store.addServices( 'casManagement', 'files' ); 14 | let fileList = store.apiCall( files.links( 'files' ) ); 15 | let casMangementLinks = casManagement.links().toJS() 16 | console.log( fileList.itemsList().toJS() ); 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /quicktest.js: -------------------------------------------------------------------------------- 1 | const restaf = require("@sassoftware/restaf"); 2 | const restaflib = require("@sassoftware/restaflib"); 3 | 4 | let logonPayload = { 5 | host : process.env.VIYA_SERVER, 6 | token : getToken(), 7 | tokenType: "bearer", 8 | authType : "server", 9 | }; 10 | 11 | 12 | let store = restaf.initStore( 13 | { casProxy: true, 14 | options : { 15 | proxyServer: null 16 | }}); 17 | 18 | run() 19 | .then((r) => console.log("done")) 20 | .catch((err) => console.log(JSON.stringify(err, null, 4))); 21 | async function run() { 22 | let msg = await store.logon(logonPayload); 23 | console.log(msg); 24 | let { casManagement } = await store.addServices("casManagement"); 25 | let { session } = await restaflib.casSetup(store, null); 26 | 27 | let p = { 28 | action: "datastep.runCode", 29 | data : { 30 | single: "YES", 31 | code : "data casuser.score; keep x1 x2;do i = 1 to 20; x1=i; x2=i*10;output;end;run; ", 32 | }, 33 | }; 34 | let r = await store.runAction(session, p); 35 | console.log('-----------------'); 36 | console.log(r.items().toJS()); 37 | 38 | console.log("-------------------------"); 39 | p = { 40 | action: "builtins.echo", 41 | data : { 42 | code: "data casuser.score; x1=10;x2=20;x3=30; score1 = x1+x2+x3;run; ", 43 | }, 44 | }; 45 | let r1 = await store.runAction(session, p); 46 | 47 | console.log(r1.items().toJS()); 48 | 49 | return "done"; 50 | } 51 | 52 | function getToken() { 53 | let fs = require("fs"); 54 | let j = fs.readFileSync(process.env.SASTOKEN, "utf8"); 55 | let js = JSON.parse(j); 56 | let token = js.Default["access-token"]; 57 | console.log("token", token); 58 | return token; 59 | } 60 | --------------------------------------------------------------------------------