Coder Social home page Coder Social logo

js-faas's Introduction

Js-Faas (WIP)

Node.Js SDK for OpenFaaS

How to use

Install

	npm i -g @vitwit/js-faas

Create a client

	import 'js-faas';
	
	var jsFaas = new JsFaas({})
getFunctions

getFunctions

Example

const  { data, error } = await jsFaas.getFunctions()

Responses

Success 2XX

{
  "200": {
    "description": "List of deployed functions.",
    "schema": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/FunctionListEntry"
      }
    }
  }
}
FunctionListEntry
createFunction

createFunction

Example

const  { data, error } = await jsFaas.createFunction({
 "service": "nodeinfo",
 "network": "func_functions",
 "image": "functions/nodeinfo:latest",
 "envProcess": "node main.js",
 "envVars": {
   "additionalProp1": "string",
   "additionalProp2": "string",
   "additionalProp3": "string"
 },
 "constraints": [
   "node.platform.os == linux"
 ],
 "labels": {
   "foo": "bar"
 },
 "annotations": {
   "topics": "awesome-kafka-topic",
   "foo": "bar"
 },
 "secrets": [
   "secret-name-1"
 ],
 "registryAuth": "dXNlcjpwYXNzd29yZA==",
 "limits": {
   "memory": "128M",
   "cpu": "0.01"
 },
 "requests": {
   "memory": "128M",
   "cpu": "0.01"
 },
 "readOnlyRootFilesystem": true
})

Responses

Success 2XX

{
  "202": {
    "description": "Accepted"
  }
}

Error 4XX

{
  "400": {
    "description": "Bad Request"
  }
}

Error 5XX

{
  "500": {
    "description": "Internal Server Error"
  }
}
FunctionDefintion FunctionListEntry
updateFunction

updateFunction

Example

const  { data, error } = await jsFaas.updateFunction({
 /** FunctionDefintion modal, description-Function to update,required-true */
})

Responses

Success 2XX

{
  "200": {
    "description": "Accepted"
  }
}

Error 4XX

{
  "400": {
    "description": "Bad Request"
  },
  "404": {
    "description": "Not Found"
  }
}

Error 5XX

{
  "500": {
    "description": "Internal Server Error"
  }
}
FunctionDefintion FunctionDefintion FunctionListEntry
deleteFunction

deleteFunction

Example

const  { data, error } = await jsFaas.deleteFunction({
 /** DeleteFunctionRequest modal, description-Function to delete,required-true */
})

Responses

Success 2XX

{
  "200": {
    "description": "OK"
  }
}

Error 4XX

{
  "400": {
    "description": "Bad Request"
  },
  "404": {
    "description": "Not Found"
  }
}

Error 5XX

{
  "500": {
    "description": "Internal Server Error"
  }
}
FunctionDefintion FunctionDefintion DeleteFunctionRequest FunctionListEntry
handleAlert

handleAlert

Example

const  { data, error } = await jsFaas.handleAlert({
 /** undefined modal,type - object, description-Incoming alert */
})

Responses

Success 2XX

{
  "200": {
    "description": "Alert handled successfully"
  }
}

Error 5XX

{
  "500": {
    "description": "Internal error with swarm or request JSON invalid"
  }
}
FunctionDefintion FunctionDefintion DeleteFunctionRequest undefined FunctionListEntry
invokeFunctionAsync

invokeFunctionAsync

Example

const  { data, error } = await jsFaas.invokeFunctionAsync({
input:undefined, /** description-(Optional) data to pass to function,required-false */
 _pathParams: {
  functionName:string, /** description-Function name,required-true */ 
 }
})

Responses

Success 2XX

{
  "202": {
    "description": "Request accepted and queued"
  }
}

Error 4XX

{
  "404": {
    "description": "Not Found"
  }
}

Error 5XX

{
  "500": {
    "description": "Internal Server Error"
  }
}
FunctionDefintion FunctionDefintion DeleteFunctionRequest undefined FunctionListEntry
invokeFunction

invokeFunction

Example

const  { data, error } = await jsFaas.invokeFunction({
input:undefined, /** description-(Optional) data to pass to function,required-false */
 _pathParams: {
  functionName:string, /** description-Function name,required-true */ 
 }
})

Responses

Success 2XX

{
  "200": {
    "description": "Value returned from function"
  }
}

Error 4XX

{
  "404": {
    "description": "Not Found"
  }
}

Error 5XX

{
  "500": {
    "description": "Internal server error"
  }
}
FunctionDefintion FunctionDefintion DeleteFunctionRequest undefined FunctionListEntry
scaleFunction

scaleFunction

Example

const  { data, error } = await jsFaas.scaleFunction({
input:undefined, /** description-Function to scale plus replica count,required-false */
 _pathParams: {
  functionName:string, /** description-Function name,required-true */ 
 }
})

Responses

Success 2XX

{
  "200": {
    "description": "Scaling OK"
  },
  "202": {
    "description": "Scaling OK"
  }
}

Error 4XX

{
  "404": {
    "description": "Function not found"
  }
}

Error 5XX

{
  "500": {
    "description": "Error scaling function"
  }
}
FunctionDefintion FunctionDefintion DeleteFunctionRequest undefined FunctionListEntry
getFunctionSummary

getFunctionSummary

Example

const  { data, error } = await Faasjs.getFunctionSummary({
 _pathParams: {
  functionName:string, /** description-Function name,required-true */ 
 }
})

Responses

Success 2XX

{
  "200": {
    "description": "Function Summary",
    "schema": {
      "$ref": "#/definitions/FunctionListEntry"
    }
  }
}

Error 4XX

{
  "404": {
    "description": "Not Found"
  }
}

Error 5XX

{
  "500": {
    "description": "Internal Server Error"
  }
}
FunctionDefintion FunctionDefintion DeleteFunctionRequest undefined FunctionListEntry FunctionListEntry
getSecrets

getSecrets

Example

const  { data, error } = await jsFaas.getSecrets({

})

Responses

Success 2XX

{
  "200": {
    "description": "List of submitted secrets.",
    "schema": {
      "$ref": "#/definitions/SecretName"
    }
  }
}
FunctionDefintion FunctionDefintion DeleteFunctionRequest undefined FunctionListEntry FunctionListEntry SecretName
createSecret

createSecret

Example

const  { data, error } = await jsFaas.createSecret({
 /** Secret modal, description-A new secret to create,required-true */
})

Responses

Success 2XX

{
  "201": {
    "description": "Created"
  }
}

Error 4XX

{
  "400": {
    "description": "Bad Request"
  }
}

Error 5XX

{
  "500": {
    "description": "Internal Server Error"
  }
}
FunctionDefintion FunctionDefintion DeleteFunctionRequest undefined Secret FunctionListEntry FunctionListEntry SecretName
updateSecret

updateSecret

Example

const  { data, error } = await jsFaas.updateSecret({
 /** Secret modal, description-Secret to update,required-true */
})

Responses

Success 2XX

{
  "200": {
    "description": "Ok"
  }
}

Error 4XX

{
  "400": {
    "description": "Bad Request"
  },
  "404": {
    "description": "Not Found"
  }
}

Error 5XX

{
  "500": {
    "description": "Internal Server Error"
  }
}
FunctionDefintion FunctionDefintion DeleteFunctionRequest undefined Secret Secret FunctionListEntry FunctionListEntry SecretName
deleteSecret

deleteSecret

Example

const  { data, error } = await jsFaas.deleteSecret({
 /** SecretName modal, description-Secret to delete,required-true */
})

Responses

Success 2XX

{
  "204": {
    "description": "OK"
  }
}

Error 4XX

{
  "400": {
    "description": "Bad Request"
  },
  "404": {
    "description": "Not Found"
  }
}

Error 5XX

{
  "500": {
    "description": "Internal Server Error"
  }
}
FunctionDefintion FunctionDefintion DeleteFunctionRequest undefined Secret Secret SecretName FunctionListEntry FunctionListEntry SecretName
getLogsOfAFunction

getLogsOfAFunction

Example

const  { data, error } = await jsFaas.getLogsOfAFunction({
 _params: {
  name:string, /** description-Function name,required-true */ 
  since:string, /** description-Only return logs after a specific date (RFC3339),required-false */ 
  tail:integer, /** description-Sets the maximum number of log messages to return, <=0 means unlimited,required-false */ 
  follow:boolean, /** description-When true, the request will stream logs until the request timeout,required-false */ 
 }
})

Responses

Success 2XX

{
  "200": {
    "description": "Newline delimited stream of log messages",
    "schema": {
      "$ref": "#/definitions/LogEntry"
    }
  }
}

Error 4XX

{
  "404": {
    "description": "Not Found"
  }
}

Error 5XX

{
  "500": {
    "description": "Internal Server Error"
  }
}
FunctionDefintion FunctionDefintion DeleteFunctionRequest undefined Secret Secret SecretName FunctionListEntry FunctionListEntry SecretName LogEntry
getInfo

getInfo

Example

const  { data, error } = await jsFaas.getInfo({

})

Responses

Success 2XX

{
  "200": {
    "description": "Info result",
    "schema": {
      "$ref": "#/definitions/Info"
    }
  }
}

Error 4XX

{
  "404": {
    "description": "Provider does not support info endpoint"
  }
}

Error 5XX

{
  "500": {
    "description": "Internal Server Error"
  }
}
FunctionDefintion FunctionDefintion DeleteFunctionRequest undefined Secret Secret SecretName FunctionListEntry FunctionListEntry SecretName LogEntry Info
checkHealth

checkHealth

Example

const  { data, error } = await jsFaas.checkHealth({

})

Responses

Success 2XX

{
  "200": {
    "description": "Healthy"
  }
}

Error 5XX

{
  "500": {
    "description": "Not healthy"
  }
}
FunctionDefintion FunctionDefintion DeleteFunctionRequest undefined Secret Secret SecretName FunctionListEntry FunctionListEntry SecretName LogEntry Info

Modal Definations

Info-modal

{
 "type": "object",
 "properties": {
   "provider": {
     "type": "object",
     "description": "The OpenFaaS Provider",
     "properties": {
       "provider": {
         "type": "string",
         "example": "faas-swarm"
       },
       "orchestration": {
         "type": "string",
         "example": "swarm"
       },
       "version": {
         "type": "object",
         "description": "Version of the OpenFaaS Provider",
         "properties": {
           "commit_message": {
             "type": "string",
             "example": "Sample Message"
           },
           "sha": {
             "type": "string",
             "example": "7108418d9dd6b329ddff40e7393b3166f8160a88"
           },
           "release": {
             "type": "string",
             "format": "semver",
             "example": "0.2.6"
           }
         }
       }
     }
   },
   "version": {
     "type": "object",
     "description": "Version of the Gateway",
     "properties": {
       "commit_message": {
         "type": "string",
         "example": "Sample Message"
       },
       "sha": {
         "type": "string",
         "example": "7108418d9dd6b329ddff40e7393b3166f8160a88"
       },
       "release": {
         "type": "string",
         "format": "semver",
         "example": "0.8.9"
       }
     }
   },
   "arch": {
     "type": "string",
     "description": "Platform architecture",
     "example": "x86_64"
   }
 },
 "required": [
   "provider",
   "version"
 ]
}

DeleteFunctionRequest-modal

{
 "type": "object",
 "properties": {
   "functionName": {
     "type": "string",
     "description": "Name of deployed function",
     "example": "nodeinfo"
   }
 },
 "required": [
   "functionName"
 ]
}

FunctionDefintion-modal

{
 "type": "object",
 "properties": {
   "service": {
     "type": "string",
     "description": "Name of deployed function",
     "example": "nodeinfo"
   },
   "network": {
     "type": "string",
     "description": "Docker swarm network, usually func_functions",
     "example": "func_functions"
   },
   "image": {
     "type": "string",
     "description": "Docker image in accessible registry",
     "example": "functions/nodeinfo:latest"
   },
   "envProcess": {
     "type": "string",
     "description": "Process for watchdog to fork",
     "example": "node main.js"
   },
   "envVars": {
     "type": "object",
     "additionalProperties": {
       "type": "string"
     },
     "description": "Overrides to environmental variables"
   },
   "constraints": {
     "type": "array",
     "items": {
       "type": "string",
       "description": "Constraints are specific to OpenFaaS Provider",
       "example": "node.platform.os == linux"
     }
   },
   "labels": {
     "description": "A map of labels for making scheduling or routing decisions",
     "type": "object",
     "additionalProperties": {
       "type": "string"
     },
     "example": {
       "foo": "bar"
     }
   },
   "annotations": {
     "description": "A map of annotations for management, orchestration, events and build tasks",
     "type": "object",
     "additionalProperties": {
       "type": "string"
     },
     "example": {
       "topics": "awesome-kafka-topic",
       "foo": "bar"
     }
   },
   "secrets": {
     "type": "array",
     "items": {
       "type": "string",
       "description": "An array of names of secrets that are required to be loaded from the Docker Swarm.",
       "example": "secret-name-1"
     }
   },
   "registryAuth": {
     "type": "string",
     "description": "Private registry base64-encoded basic auth (as present in ~/.docker/config.json)",
     "example": "dXNlcjpwYXNzd29yZA=="
   },
   "limits": {
     "type": "object",
     "properties": {
       "memory": {
         "type": "string",
         "example": "128M"
       },
       "cpu": {
         "type": "string",
         "example": "0.01"
       }
     }
   },
   "requests": {
     "type": "object",
     "properties": {
       "memory": {
         "type": "string",
         "example": "128M"
       },
       "cpu": {
         "type": "string",
         "example": "0.01"
       }
     }
   },
   "readOnlyRootFilesystem": {
     "type": "boolean",
     "description": "Make the root filesystem of the function read-only"
   }
 },
 "required": [
   "service",
   "image",
   "envProcess"
 ]
}

FunctionListEntry-modal

{
 "type": "object",
 "properties": {
   "name": {
     "description": "The name of the function",
     "type": "string",
     "example": "nodeinfo"
   },
   "image": {
     "description": "The fully qualified docker image name of the function",
     "type": "string",
     "example": "functions/nodeinfo:latest"
   },
   "invocationCount": {
     "description": "The amount of invocations for the specified function",
     "type": "number",
     "format": "integer",
     "example": 1337
   },
   "replicas": {
     "description": "The current minimal ammount of replicas",
     "type": "number",
     "format": "integer",
     "example": 2
   },
   "availableReplicas": {
     "description": "The current available amount of replicas",
     "type": "number",
     "format": "integer",
     "example": 2
   },
   "envProcess": {
     "description": "Process for watchdog to fork",
     "type": "string",
     "example": "node main.js"
   },
   "labels": {
     "description": "A map of labels for making scheduling or routing decisions",
     "type": "object",
     "additionalProperties": {
       "type": "string"
     },
     "example": {
       "foo": "bar"
     }
   },
   "annotations": {
     "description": "A map of annotations for management, orchestration, events and build tasks",
     "type": "object",
     "additionalProperties": {
       "type": "string"
     },
     "example": {
       "topics": "awesome-kafka-topic",
       "foo": "bar"
     }
   }
 },
 "required": [
   "name",
   "image",
   "invocationCount",
   "replicas",
   "availableReplicas",
   "envProcess",
   "labels"
 ]
}

Secret-modal

{
 "type": "object",
 "properties": {
   "name": {
     "type": "string",
     "description": "Name of secret",
     "example": "aws-key"
   },
   "value": {
     "type": "string",
     "description": "Value of secret in plain-text",
     "example": "changeme"
   }
 },
 "required": [
   "name"
 ]
}

LogEntry-modal

{
 "type": "object",
 "properties": {
   "name": {
     "type": "string",
     "description": "the function name"
   },
   "instance": {
     "type": "string",
     "description": "the name/id of the specific function instance"
   },
   "timestamp": {
     "type": "string",
     "format": "date-time",
     "description": "the timestamp of when the log message was recorded"
   },
   "text": {
     "type": "string",
     "description": "raw log message content"
   }
 }
}

SecretName-modal

{
 "type": "object",
 "properties": {
   "name": {
     "type": "string",
     "description": "Name of secret",
     "example": "aws-key"
   }
 }
}

js-faas's People

Contributors

anilcse avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.