🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

fms-api-client

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fms-api-client

A FileMaker Data API client designed to allow easier interaction with a FileMaker application from a web environment.

1.8.0
Version published
Weekly downloads
30
-28.57%
Maintainers
1
Weekly downloads
 
Created

fms-api-client

Build Status Known Vulnerabilities Coverage Status GitHub issues Github commits (since latest release) code style: prettier GitHub license

A FileMaker Data API client designed to allow easier interaction with a FileMaker application from a web environment. This client abstracts the FileMaker 17 Data API into class based methods. You can find detailed documentation on this project here:

fms-api-client documentation

Installation

npm install --save fms-api-client

Usage

Introduction

The fms-api-client is a wrapper around the FileMaker Data API. Much :heart: to FileMaker for their work on the Data API. This client attempts to follow the terminology used by FileMaker wherever possible. The client uses a lightweight datastore to hold Data API connections. Each client has methods which are modeled after the Data API endpoints.

fms-api-client requires that you first connect to a datastore before creating or querying the FileMaker class. Once connected you can use the datastore to save a multitude of clients.

Each client committed to the datastore will automatically handle Data API Sessions. If needed the clients can manually open or close their FileMaker sessions by calling either the client.login() method or the client.logout() method.

To remove a client from a datastore and log out a session call client.destroy().

The client supports the same parameter syntax as is found in the Data API Documentation. Where appropriate and useful the client also allows additional parameters.

Any method that accepts script or portals in query or body parameters will also accept the following script and portal parameter syntax:

Script Array Syntax

The custom script parameter follows the following syntax:

{
  "scripts": [
    {
      "name": "At Mos Eisley",
      "phase": "presort",
      "param": "awesome bar"
    },
    {
      "name": "First Shot",
      "phase": "prerequest",
      "param": "Han"
    },
    {
      "name": "Moof Milker",
      "param": "Greedo"
    }
  ]
}

File ./examples/schema/scripts-array-schema.json

Portals Array Syntax

The custom portals parameter follows the following syntax:

{
  "portals": [
    { "name": "planets", "limit": 1, "offset": 1 },
    { "name": "vehicles", "limit": 2 }
  ]
}

File ./examples/schema/portals-array-schema.json

Note: The FileMaker script and portal syntax will override the alternative scripts and portals parameter syntax.

In addition to allowing an exanded syntax for invoking scripts or selecting portals the client will also automatically parse arrays, objects, and numbers to adhere to the requirements of the Data API.

Data Syntax

{
  "data": {
    "name": "Yoda",
    "Vehicles::name": "The Force"
  }
}

File ./examples/schema/data-schema.json

Arrays and objects are stringified before being inserted into field or portal data. limit and offset parameters can be either strings or a numbers.

The client will also automatically convert limit, find, and offset parameters into their underscored conterparts as needed. Additionally, if a script result can be parsed as JSON it will be automatically parsed for you by the client.

The client accepts the same sort parameters as the Data API.

Sort Syntax

{
  "sort": [
    { "fieldName": "name", "sortOrder": "ascend" },
    { "fieldName": "modificationTimestamp", "sortOrder": "descend" }
  ]
}

File ./examples/schema/sort-schema.json

When using the find method a query is required. The query can either be a single json object or an array of json objects.

Query Syntax

{
  "query": [
    {
      "name": "Han solo",
      "Vehicles::name": "Millenium Falcon"
    },
    {
      "name": "Luke Skywalker",
      "Vehicles::name": "X-Wing Starfighter"
    },
    {
      "age": ">10000"
    }
  ]
}

File ./examples/schema/query-schema.json

All methods on the client return promises and each method will reject with a message and code upon encountering an error. All messages and codes follow the FileMaker Data API codes where applicable.

fms-api-client also provides utility modules to aid in working with FileMaker Data API Results. The provided utility modules are fieldData, recordId, and transform. These utilities will accept and return either an object or an an array objects. For more information on the utility modules see the utility section.

Datastore Connection

The connect method must be called before the FileMaker class is used. The connect method is not currently exposed by fms-api-client, but from the marpat dependency. marpat is a fork of camo. Thanks and love to Scott Robinson for his creation and maintenance of camo.

marpat is designed to allow the use of multiple datastores with the focus on encrypted file storage and project flexibility.

For more information on marpat and the different types of supported storage visit marpat

const { connect } = require('marpat');
connect('nedb://memory')

Excerpt from ./examples/index.js

Client Creation

After connecting to a datastore you can import and create clients. A client is created using the create method on the Filemaker class. The FileMaker class accepts an object with the following properties:

PropertyTypeDescription
applicationStringrequired The FileMaker application / database to connect to
serverStringrequired The FileMaker server to use as the host. Note: Must be an http or https Domain.
userStringrequired The FileMaker user account to be used when authenticating into the Data API
passwordStringrequired The FileMaker user account's password.
nameStringoptional A name for the client.
usageBooleanoptional Track Data API usage for this client. Note: Default is true
timeoutNumberoptional The default timeout time for requests Note: Default is 0, (no timeout)
proxyObjectoptional settings for a proxy server
agentObjectoptional settings for a custom request agent

:warning: You should only use the agent parameter when absolutely necessary. The Data API was designed to be used on https. Deviating from the intended use should be done with caution.

    const client = Filemaker.create({
      name: process.env.CLIENT_NAME,
      application: process.env.APPLICATION,
      server: process.env.SERVER,
      user: process.env.USERNAME,
      password: process.env.PASSWORD,
      usage: process.env.CLIENT_USAGE_TRACKING,
      agent: { rejectUnauthorized: false }
    });

Excerpt from ./examples/index.js

Note: The server must be an http or https domain.

A client can be used directly after saving it. The client.save() method takes no arguments and will either reject with an error or resolve with a useable client. The client will automatically handle Data API session creation and expiration. Once a client is saved it will be stored on the datastore for reuse later.

    return client.save();
  })
  .then(client => authentication(client))
  .then(client => creates(client))
  .then(client => gets(client))
  .then(client => lists(client))
  .then(client => finds(client))
  .then(client => edits(client))
  .then(client => scripts(client))
  .then(client => globals(client))
  .then(client => deletes(client))
  .then(client => uploads(client))
  .then(client => utilities(client))

Excerpt from ./examples/index.js

A client can be removed using either the client.destroy() method, the Filemaker.deleteOne(query) method or the Filemaker.deleteMany(query) method.

Note Only the client.destroy() method will close a FileMaker session. Any client removed using the the Filemaker.deleteOne(query) method or the Filemaker.deleteMany(query) method will not log out before being destroyed.

Client Use

A client can be used after it is created and saved or recalled from the datastore. The Filemaker.find(query) or Filemaker.findOne(query) methods can be used to recall clients. The Filemaker.findOne(query) method will return either one client or null. The Filemaker.find(query) will return either an empty array or an array of clients. All public methods on the client return promises.

const createManyRecords = client =>
  Promise.all([
    client.create('Heroes', { name: 'Anakin Skywalker' }, { merge: true }),
    client.create('Heroes', { name: 'Obi-Wan' }, { merge: true }),
    client.create('Heroes', { name: 'Yoda' }, { merge: true })
  ]).then(result => log('create-many-records-example', result));

Excerpt from ./examples/create.examples.js

Results:

[
  {
    "name": "Anakin Skywalker",
    "recordId": "1138",
    "modId": "327"
  },
  {
    "name": "Obi-Wan",
    "recordId": "1138",
    "modId": "327"
  },
  {
    "name": "Yoda",
    "recordId": "1138",
    "modId": "327"
  }
]

File ./examples/results/create-many-records-example.json

Data API Sessions

The client will automatically handle creating and closing Data API sessions. If required the client will authenticate and generate a new session token with each method call.

The Data API session is also monitored, updated, and saved as the client interacts with the Data API. A client will always attempt to reuse a valid token whenever possible.

The client contains two methods related to Data API sessions. These methods are client.login() and client.logout(). The login method is used to start a Data API session and the logout method will end a Data API session.

Login Method

The client will automatically call the login method if it does not have a valid token. This method returns an object with a token property. This method will also save the token to the client's connection for future use.

client.login()

const login = client => client.login();

Excerpt from ./examples/authentication.examples.js

Logout Method

The logout method is used to end a Data API session. This method will also remove the current client's authentication token.

client.logout()

const logout = client =>
  client
    .login()
    .then(() =>
      client.logout().then(result => log('client-logout-example', result))
    );

Excerpt from ./examples/authentication.examples.js

Create Records

Using the client you can create filemaker records. To create a record specify the layout to use and the data to insert on creation. The client will automatically convert numbers, arrays, and objects into strings so they can be inserted into a filemaker field. The create method will automatically create a fieldData property and add all data to that property if there is no fieldData property present. The client will preserve the contents of the portalData property.

client.create(layout, data, parameters)

ParamTypeDescription
layoutStringThe layout to use when creating a record.
dataObjectThe data to use when creating a record.
parametersObjectThe request parameters to use when creating the record.
const createRecord = client =>
  client
    .create('Heroes', {
      name: 'George Lucas'
    })
    .then(result => log('create-record-example', result));

Excerpt from ./examples/create.examples.js

Result:

{
  "recordId": "1138",
  "modId": "327"
}

File ./examples/results/create-record-example.json

Both the create method and the edit method accept a merge boolean in their option parameters. If the merge property is true the data used to create or edit the filemaker record will be merged with the FileMaker Data API results.

const mergeDataOnCreate = client =>
  client
    .create(
      'Heroes',
      {
        name: 'George Lucas'
      },
      { merge: true }
    )
    .then(result => log('create-record-merge-example', result));

Excerpt from ./examples/create.examples.js

Result:

{
  "name": "George Lucas",
  "recordId": "1138",
  "modId": "327"
}

File ./examples/results/create-record-merge-example.json

The create method also allows you to trigger scripts when creating a record. Notice the scripts property in the following example. You can specify scripts to run using either FileMaker's script.key syntax or specify an array of in a scripts property. The script objects should have with name, optional phase, and optional params parameters. For more information see the scripts syntax example in the introduction.

const triggerScriptsOnCreate = client =>
  client
    .create(
      'Heroes',
      { name: 'Anakin Skywalker' },
      {
        merge: true,
        scripts: [
          { name: 'Create Droids', param: { droids: ['C3-PO', 'R2-D2'] } }
        ]
      }
    )
    .then(result => log('trigger-scripts-on-create-example', result));

Excerpt from ./examples/create.examples.js

Result:

{
  "name": "Anakin Skywalker",
  "scriptError": "0",
  "recordId": "1138",
  "modId": "327"
}

File ./examples/results/trigger-scripts-on-create-example.json

Get Record Details

The Get method will return a specific FileMaker record based on the recordId passed to it. The recordId can be a string or a number.

client.get(layout, recordId, parameters)

ParamTypeDescription
layoutStringThe layout to use when retrieving the record.
recordIdStringThe FileMaker internal record ID to use when retrieving the record.
parametersObjectParameters to add for the get query.
      client
        .get('Heroes', response.data[0].recordId)
        .then(result => log('get-record-example', result))

Excerpt from ./examples/get.examples.js

Result:

{
  "data": [
    {
      "fieldData": {
        "name": "yoda",
        "image": "",
        "object": "",
        "array": "",
        "height": "",
        "id": "r2d2-c3po-l3-37-bb-8",
        "imageName": "",
        "creationAccountName": "obi-wan",
        "creationTimestamp": "05/25/1977 6:00:00",
        "modificationAccountName": "obi-wan",
        "modificationTimestamp": "05/25/1977 6:00:00",
        "Vehicles::name": ""
      },
      "portalData": {
        "Planets": [],
        "Vehicles": []
      },
      "recordId": "1138",
      "modId": "327"
    }
  ]
}

File ./examples/results/get-record-example.json

List Records

You can use the client to list filemaker records. The list method accepts a layout and parameter variable. The client will automatically santize the limit, offset, and sort keys to correspond with the DAPI's requirements.

client.list(layout, parameters)

ParamTypeDescription
layoutStringThe layout to use when retrieving the record.
parametersObjectthe parameters to use to modify the query.
const listHeroes = client =>
  client
    .list('Heroes', { limit: 2 })
    .then(result => log('list-records-example', result));

Excerpt from ./examples/list.examples.js

Result:

{
  "data": [
    {
      "fieldData": {
        "name": "George Lucas",
        "image": "https://some-server.com/Streaming_SSL/MainDB/6E811926D311DA7F5D695B1E267AFE9ABD06A41558EBFA0027319542040A56DB.png?RCType=EmbeddedRCFileProcessor",
        "object": "",
        "array": "",
        "height": "",
        "id": "r2d2-c3po-l3-37-bb-8",
        "imageName": "IMG_0001.PNG",
        "creationAccountName": "obi-wan",
        "creationTimestamp": "05/25/1977 6:00:00",
        "modificationAccountName": "obi-wan",
        "modificationTimestamp": "05/25/1977 6:00:00",
        "Vehicles::name": "test"
      },
      "portalData": {
        "Planets": [],
        "Vehicles": [
          {
            "recordId": "1138",
            "Vehicles::name": "test",
            "Vehicles::type": "",
            "modId": "327"
          }
        ]
      },
      "recordId": "1138",
      "modId": "327"
    },
    {
      "fieldData": {
        "name": "George Lucas",
        "image": "",
        "object": "",
        "array": "",
        "height": "",
        "id": "r2d2-c3po-l3-37-bb-8",
        "imageName": "",
        "creationAccountName": "obi-wan",
        "creationTimestamp": "05/25/1977 6:00:00",
        "modificationAccountName": "obi-wan",
        "modificationTimestamp": "05/25/1977 6:00:00",
        "Vehicles::name": ""
      },
      "portalData": {
        "Planets": [],
        "Vehicles": []
      },
      "recordId": "1138",
      "modId": "327"
    }
  ]
}

File ./examples/results/list-records-example.json

Find Records

The client's find method will accept either a single object as find parameters or an array. The find method will also santize the limit, sort, and offset parameters to conform with the Data API's requirements.

client.find(layout, query, parameters)

ParamTypeDescription
layoutStringThe layout to use when performing the find.
queryObjectto use in the find request.
parametersObjectthe parameters to use to modify the query.
const findRecords = client =>
  client
    .find('Heroes', [{ name: 'Anakin Skywalker' }], { limit: 1 })
    .then(result => log('find-records-example', result));

Excerpt from ./examples/find.examples.js

Result:

{
  "data": [
    {
      "fieldData": {
        "name": "Anakin Skywalker",
        "image": "",
        "object": "",
        "array": "",
        "height": "",
        "id": "r2d2-c3po-l3-37-bb-8",
        "imageName": "",
        "creationAccountName": "obi-wan",
        "creationTimestamp": "05/25/1977 6:00:00",
        "modificationAccountName": "obi-wan",
        "modificationTimestamp": "05/25/1977 6:00:00",
        "Vehicles::name": ""
      },
      "portalData": {
        "Planets": [],
        "Vehicles": []
      },
      "recordId": "1138",
      "modId": "327"
    }
  ]
}

File ./examples/results/find-records-example.json

Edit Records

The client's edit method requires a layout, recordId, and object to use for updating the record.

client.edit(layout, recordId, data, parameters)

ParamTypeDescription
layoutStringThe layout to use when editing the record.
recordIdStringThe FileMaker internal record ID to use when editing the record.
dataObjectThe data to use when editing a record.
parametersObjectparameters to use when performing the query.
const editRecord = client =>
  client
    .find('Heroes', [{ name: 'Anakin Skywalker' }], { limit: 1 })
    .then(response => response.data[0].recordId)
    .then(recordId => client.edit('Heroes', recordId, { name: 'Darth Vader' }))
    .then(result => log('edit-record-example', result));

Excerpt from ./examples/edit.examples.js

Result:

{
  "modId": "327"
}

File ./examples/results/edit-record-example.json

Delete Records

The client's delete method requires a layout and a record id. The recordId can be a number or a string.

client.delete(layout, recordId, parameters)

ParamTypeDescription
layoutStringThe layout to use when deleting the record.
recordIdStringThe FileMaker internal record ID to use when editing the record.
const deleteRecords = client =>
  client
    .find('Heroes', [{ name: 'yoda' }], { limit: 1 })
    .then(response => response.data[0].recordId)
    .then(recordId => client.delete('Heroes', recordId))
    .then(result => log('delete-record-example', result));

Excerpt from ./examples/delete.examples.js

Result:

{}

File ./examples/results/delete-record-example.json

Trigger Script

The client's script method will trigger a script. You can also trigger scripts with the create, edit, list, find, and delete methods. This method performs a list with a limit of one on the specified layout before triggering the script. this is the most lightweight request possible while still being able to trigger a script.

client.script(layout, script, param, parameters)

ParamTypeDescription
layoutStringThe layout to use for the list request
nameStringThe name of the script
parametersObjectParameters to pass to the script
const triggerScript = client =>
  client
    .script('Heroes', 'FMS Triggered Script', { name: 'Han' })
    .then(result => log('script-trigger-example', result));

Excerpt from ./examples/script.examples.js

Result:

{
  "result": {
    "answer": "Han shot first"
  }
}

File ./examples/results/script-trigger-example.json

Upload Files

The upload method will upload binary data to a container. The file parameter should be either a path to a file or a buffer. If you need to set a field repetition, you can set that in parameters. If recordId is 0 or undefined a new record will be created.

client.upload(file, layout, container, recordId, parameters)

ParamTypeDescription
fileStringThe path to the file to upload.
layoutStringThe layout to use when performing the find.
containerFieldNameStringThe field name to insert the data into. It must be a container field.
recordIdNumber | Stringthe recordId to use when uploading the file.
fieldRepetitionNumberThe field repetition to use when inserting into a container field. by default this is 1.
const uploadImage = client =>
  client
    .upload('./assets/placeholder.md', 'Heroes', 'image')
    .then(result => log('upload-image-example', result));

Excerpt from ./examples/upload.examples.js

Result:

{
  "modId": "327",
  "recordId": "1138"
}

File ./examples/results/upload-image-example.json

You can also provide a record Id to the upload method and the file will be uploaded to that record.

          client
            .upload('./assets/placeholder.md', 'Heroes', 'image', recordId)
            .then(result => log('upload-specific-record-example', result))
            .catch(error => error),

Excerpt from ./examples/upload.examples.js

Result:

{
  "modId": "327",
  "recordId": "1138"
}

File ./examples/results/upload-specific-record-example.json

Set Session Globals

The globals method will set global fields for the current session.

client.globals(data, parameters)

ParamTypeDescription
dataObject | Arraya json object containing the name value pairs to set.
const setGlobals = client =>
  client
    .globals({ 'Globals::ship': 'Millenium Falcon' })
    .then(result => log('set-globals-example', result));

Excerpt from ./examples/globals.examples.js

Result:

{}

File ./examples/results/set-globals-example.json

Utility Methods

The client also provides utility methods to aid in parsing and manipulating FileMaker Data. The client exports the recordId(data), fieldData(data), and transform(data, options) to aid in transforming Data API response data into other formats. Each utility method is capable of recieving either an object or a array.

recordId Method

The recordId method retrieves the recordId properties for a response. This method will return either a single string or an array of strings.

recordId(data)

ParamTypeDescription
dataObject | Arraythe raw data returned from a filemaker. This can be an array or an object.
const extractRecordId = client =>
  client
    .find('Heroes', { name: 'yoda' }, { limit: 2 })
    .then(response => recordId(response.data))
    .then(result => log('recordid-utility-example', result));

Excerpt from ./examples/utility.examples.js

Result:

[
  "737039",
  "737040"
]

File ./examples/results/recordid-utility-example.json

fieldData Method

The fieldData method retrieves the fieldData, recordId, and modId properties from a Data API response. The fieldData method will merge the recordId and modId properties into fielData properties. This method will not convert table::field properties.

fieldData(data)

ParamTypeDescription
dataObject | ArrayThe raw data returned from a filemaker. This can be an array or an object.
const extractFieldData = client =>
  client
    .find('Heroes', { name: 'yoda' }, { limit: 2 })
    .then(response => fieldData(response.data))
    .then(result => log('fielddata-utility-example', result));

Excerpt from ./examples/utility.examples.js

Result:

[
  {
    "name": "Yoda",
    "image": "https://some-server.com/Streaming_SSL/MainDB/EC9C1C75788553018B0601A4E77B1C46BAC4114DBD75BE96F4AEA218D52B31B3?RCType=EmbeddedRCFileProcessor",
    "object": "",
    "array": "",
    "height": "",
    "id": "r2d2-c3po-l3-37-bb-8",
    "imageName": "placeholder.md",
    "creationAccountName": "obi-wan",
    "creationTimestamp": "05/25/1977 6:00:00",
    "modificationAccountName": "obi-wan",
    "modificationTimestamp": "05/25/1977 6:00:00",
    "Vehicles::name": "",
    "recordId": "1138",
    "modId": "327"
  },
  {
    "name": "yoda",
    "image": "",
    "object": "",
    "array": "",
    "height": "",
    "id": "r2d2-c3po-l3-37-bb-8",
    "imageName": "",
    "creationAccountName": "obi-wan",
    "creationTimestamp": "05/25/1977 6:00:00",
    "modificationAccountName": "obi-wan",
    "modificationTimestamp": "05/25/1977 6:00:00",
    "Vehicles::name": "",
    "recordId": "1138",
    "modId": "327"
  }
]

File ./examples/results/fielddata-utility-example.json

Transform Utility

The transform utility converts Data API response data by converting table::field properties to objects. This method will transverse the response data and converting { table::field : value} properties to { table:{ field : value } }. The transform utility will also convert portalData into arrays of objects.

The transform utility accepts three option properties. The three option properties are all booleans and true by default. The three option properties are convert,fieldData,portalData. The convert property controls the transfomation of table::field properties. The fieldData property controls the merging of fieldData to the result. The portalData property controls the merging of portalData to the result. Setting any propery to false its transformation off.

transform(data, parameters)

ParamTypeDescription
objectObjectThe response recieved from the FileMaker DAPI.
const transformData = client =>
  client
    .find('Transform', { name: 'Han Solo' }, { limit: 1 })
    .then(result => transform(result.data))
    .then(result => log('transform-utility-example', result));

Excerpt from ./examples/utility.examples.js

Result:

[
  {
    "starships": "",
    "vehicles": "",
    "species": "",
    "biography": "",
    "birthYear": "",
    "id": "r2d2-c3po-l3-37-bb-8",
    "name": "Han Solo",
    "Planets": [
      {
        "recordId": "1138",
        "name": "Coriella",
        "modId": "327"
      }
    ],
    "Vehicles": [
      {
        "recordId": "1138",
        "name": "Millenium Falcon",
        "type": "Starship",
        "modId": "327"
      }
    ],
    "recordId": "1138",
    "modId": "327"
  }
]

File ./examples/results/transform-utility-example.json

ContainerData Utility

The containerData utility will retrieve FileMaker container data by following the links returned by the Data API. This utility will accept either a single data object or an array of objects. The utility will use the field parameter to target container data urls in the data parameter. This utility also requires a name parameter which will be used to target a data property that should be used as the file's name. If a name parameter is provided that is not a property or nested property in the data parameter, the name parameter itself will be used. The destination parameter should be either 'buffer' to indicate that an object with a file's name and buffer should be returned or the path, relative to the current working directory, where the utility should write container data to a file. This utility will also accept optional request parameters to modify the http request.

container(data, field, destination, name, parameters)

ParamTypeDescription
dataObject | ArrayThe response recieved from the FileMaker DAPI.
fieldStringThe container field name to target. This can be a nested property.
destinationString"buffer" if a buffer object should be returned or the path to write the file.
nameStringThe field to use for the file name or a static string.
[parameters]Objectrequest parameters.
[parameters.timeout]Numbera timeout for the request.
const transformData = client =>
  client
    .find('Transform', { name: 'Han Solo' }, { limit: 1 })
    .then(result => transform(result.data))
    .then(result => log('transform-utility-example', result));

Excerpt from ./examples/utility.examples.js

Result:

[
  {
    "name": "IMG_0001.PNG",
    "path": "assets/IMG_0001.PNG"
  }
]

File ./examples/results/containerdata-example.json

Custom Request Agents, Custom Request Parameters, and Proxies

The client has the ability to create custom agents and modify requests parameters or use a proxy. Agents, request parameters, and proxies can be configured either when the client is created or when a request is being made.

Custom Request Agents

A client can have a custom Agent. Using a custom request agent will allow you to configure an agent designed for your specific needs. A request agent can be configured to not reject unauthorized request such as those with invalid SSLs, keep the connection alive, or limit the number of sockets to a host. There is no need to create an agent unless theses options are needed.

Note If you are using a custom agent you are responsible for destroying that agent with client.destroy once the agent is no longer used.

Custom Request Parameters

All client methods except client.login() and client.logout() accept request parameters. These parameters are request.proxy and request.timeout, request.agent. These properties will apply only to the current request.

Proxies

The client can be configured to use a proxy. The proxy can be configured either for every request by specifying the proxy during the creation of the client, or just for a particular request by specifying the proxy in the request parameters.

Tests

npm install
npm test
> fms-api-client@1.8.0 test /fms-api-client
> nyc _mocha --recursive  ./tests --timeout=30000 --exit



  Agent Configuration Capabilities
    ✓ should accept no agent configuration
    ✓ should not create an agent unless one is defined (293ms)
    ✓ adjusts the request protocol according to the server
    ✓ should create a https agent
    ✓ should use a created request agent
    ✓ should destory the agent when the client is deleted
    ✓ should create a http agent
    ✓ should accept a timeout property
    ✓ should use a timeout if one is set
    ✓ should use a proxy if one is set (241ms)
    ✓ should automatically recreate an agent if one is deleted (207ms)

  Authentication Capabilities
    ✓ should authenticate into FileMaker. (91ms)
    ✓ should automatically request an authentication token (237ms)
    ✓ should reuse a saved authentication token (178ms)
    ✓ should log out of the filemaker. (186ms)
    ✓ should not attempt a logout if there is no valid token.
    ✓ should reject if the logout request fails (174ms)
    ✓ should reject if the authentication request fails (1725ms)
    ✓ should attempt to log out before being removed (170ms)
    ✓ should catch the log out error before being removed if the login is not valid

  ContainerData Capabilities
    ✓ should download container data from an object to a file (1755ms)
    ✓ should download container data from an array to a file (1532ms)
    ✓ should substitute the record id if a name is not specified (1594ms)
    ✓ should substitute the record id if a name is not specified (1480ms)
    ✓ should download container data from an array to a buffer (1534ms)
    ✓ should download container data from an object to a buffer (1533ms)
    ✓ should substitute a uuid if the record id can not be found in an object (1523ms)
    ✓ should substitute a uuid if the record id can not be found in an array (1641ms)
    ✓ should reject with an error and a message (1363ms)
    ✓ should reject if the WPE rejects the request (1534ms)

  Create Capabilities
    ✓ should create FileMaker records without fieldData (182ms)
    ✓ should allow you to specify a timeout
    ✓ should create FileMaker records using fieldData (83ms)
    ✓ should create FileMaker records with portalData (86ms)
    ✓ should allow portalData to be an object or number (88ms)
    ✓ should reject bad data with an error (80ms)
    ✓ should create records with mixed types (88ms)
    ✓ should substitute an empty object if data is not provided (81ms)
    ✓ should return an object with merged data properties (82ms)
    ✓ should allow you to run a script when creating a record with a merge response (92ms)
    ✓ should allow you to specify scripts as an array (93ms)
    ✓ should allow you to specify scripts as an array with a merge response (96ms)
    ✓ should sanitize parameters when creating a new record (94ms)
    ✓ should accept both the default script parameters and a scripts array (96ms)
    ✓ should remove an expired token (85ms)

  Delete Capabilities
    ✓ should delete FileMaker records. (265ms)
    ✓ should allow you to specify a timeout (101ms)
    ✓ should trigger scripts via an array when deleting records. (174ms)
    ✓ should trigger scripts via parameters when deleting records. (169ms)
    ✓ should allow you to mix script parameters and scripts array when deleting records. (171ms)
    ✓ should stringify script parameters. (173ms)
    ✓ should reject deletions that do not specify a recordId (81ms)
    ✓ should reject deletions that do not specify an invalid recordId (82ms)
    ✓ should remove an expired token (86ms)

  Edit Capabilities
    ✓ should edit FileMaker records without fieldData
    ✓ should allow you to specify a timeout (241ms)
    ✓ should edit FileMaker records using fieldData
    ✓ should edit FileMaker records with portalData
    ✓ should edit FileMaker records with portalData and allow portalData to be an array.
    ✓ should reject bad data with an error (185ms)
    ✓ should return an object with merged filemaker and data properties
    ✓ should allow you to run a script when editing a record (187ms)
    ✓ should allow you to run a script via a scripts array when editing a record (174ms)
    ✓ should allow you to specify scripts as an array (174ms)
    ✓ should allow you to specify scripts as an array with a merge response (236ms)
    ✓ should sanitize parameters when creating a editing record (239ms)
    ✓ should accept both the default script parameters and a scripts array (185ms)
    ✓ should remove an expired token (186ms)

  FieldData Capabilities
    ✓ it should extract field data while maintaining the array (277ms)
    ✓ it should extract field data while maintaining the object (180ms)

  Find Capabilities
    ✓ should perform a find request (349ms)
    ✓ should allow you to use an object instead of an array for a find (245ms)
    ✓ should specify omit Criterea (289ms)
    ✓ should safely parse omit true and false (151ms)
    ✓ should allow additional parameters to manipulate the results (80ms)
    ✓ should allow you to limit the number of portal records to return (85ms)
    ✓ should allow you to use numbers in the find query parameters (91ms)
    ✓ should allow you to sort the results (1267ms)
    ✓ should return an empty array if the find does not return results (130ms)
    ✓ should allow you run a pre request script (96ms)
    ✓ should return a response even if a script fails (89ms)
    ✓ should allow you to send a parameter to the pre request script (107ms)
    ✓ should allow you run script after the find and before the sort (496ms)
    ✓ should allow you to pass a parameter to a script after the find and before the sort (614ms)
    ✓ should reject of there is an issue with the find request (83ms)
    ✓ should remove an expired token (88ms)

  Get Capabilities
    ✓ should get specific FileMaker records. (272ms)
    ✓ should allow you to specify a timeout (97ms)
    ✓ should reject get requests that do not specify a recordId (165ms)
    ✓ should allow you to limit the number of portal records to return (174ms)
    ✓ should accept namespaced portal limit and offset parameters (173ms)
    ✓ should remove an expired token (134ms)

  Global Capabilities
    ✓ should allow you to set session globals (171ms)
    ✓ should allow you to specify a timeout
    ✓ should reject with a message and code if it fails to set a global (84ms)
    ✓ should remove an expired token (79ms)

  Request Interceptor Capabilities
    ✓ should reject if the server errors (122ms)
    ✓ should handle non JSON responses by rejecting with a json error (95ms)
    ✓ should reject non http requests to the server with a json error
    ✓ should reject non https requests to the server with a json error (137ms)

  List Capabilities
    ✓ should allow you to list records (345ms)
    ✓ should allow you to specify a timeout
    ✓ should allow you use parameters to modify the list response (88ms)
    ✓ should should allow you to use numbers in parameters (85ms)
    ✓ should should allow you to provide an array of portals in parameters (86ms)
    ✓ should should remove non used properties from a portal object (89ms)
    ✓ should modify requests to comply with DAPI name reservations (83ms)
    ✓ should allow strings while complying with DAPI name reservations (85ms)
    ✓ should allow you to offset the list response (80ms)
    ✓ should santize parameters that would cause unexpected parameters (85ms)
    ✓ should allow you to limit the number of portal records to return (81ms)
    ✓ should accept namespaced portal limit and offset parameters (95ms)
    ✓ should reject invalid parameters (77ms)
    ✓ should remove an expired token (78ms)

  RecordId Capabilities
    ✓ it should extract the recordId while maintaining the array (265ms)
    ✓ it should extract recordId while maintaining the object (161ms)

  Script Capabilities
    ✓ should allow you to trigger a script (195ms)
    ✓ should allow you to specify a timeout
    ✓ should allow you to trigger a script specifying a string as a parameter (86ms)
    ✓ should allow you to trigger a script specifying a number as a parameter (95ms)
    ✓ should allow you to trigger a script specifying an object as a parameter (94ms)
    ✓ should allow you to trigger a script in a find (256ms)
    ✓ should allow you to trigger a script in a list (95ms)
    ✓ should reject a script that does not exist (81ms)
    ✓ should allow return a result even if a script returns an error (94ms)
    ✓ should parse script results if the results are json (97ms)
    ✓ should not parse script results if the results are not json (88ms)
    ✓ should parse an array of scripts (91ms)
    ✓ should trigger scripts on all three script phases (103ms)
    ✓ should remove an expired token (84ms)

  Storage
    ✓ should allow an instance to be created
    ✓ should allow an instance to be saved.
    ✓ should reject if a client can not be validated
    ✓ should allow an instance to be recalled
    ✓ should allow instances to be listed
    ✓ should allow you to remove an instance

  Transform Capabilities
    ✓ should merge portal data and field data from an array (346ms)
    ✓ should merge portal data and field data from an object (156ms)
    ✓ should optionally not convert table::field keys from an array (159ms)
    ✓ should optionally not convert table::field keys from an object (156ms)
    ✓ should allow you to remove field data from an array (155ms)
    ✓ should allow you to remove field data from an object (146ms)
    ✓ should allow you to remove portal data from an array (157ms)
    ✓ should allow you to remove portal data from an object (144ms)
    ✓ should merge portal data and portal data from an array (150ms)

  File Upload Capabilities
    ✓ should allow you to specify a timeout (198ms)
    ✓ should allow you to upload a file to a new record (1285ms)
    ✓ should allow you to upload a buffer to a new record (1357ms)
    ✓ should allow you to upload a file to a specific container repetition (1563ms)
    ✓ should allow you to upload a buffer to a specific container repetition (1536ms)
    ✓ should reject with a message if it can not find the file to upload
    ✓ should allow you to upload a file to a specific record (1532ms)
    ✓ should allow you to upload a buffer object to a specific record (1536ms)
    ✓ should allow you to upload a file to a specific record container repetition (1230ms)
    ✓ should allow you to upload a buffer to a specific record container repetition (1535ms)
    ✓ should reject of the request is invalid (247ms)
    ✓ should reject an empty buffer object (83ms)
    ✓ should reject a null buffer object (84ms)
    ✓ should reject a number instead of an object (84ms)
    ✓ should reject an object without a filename (86ms)
    ✓ should reject an object without a buffer (84ms)
    ✓ should remove an expired token (85ms)

  Data Usage 
    Tracks Data Usage
      ✓ should track API usage data. (177ms)
      ✓ should allow you to reset usage data. (93ms)
    Does Not Track Data Usage
      ✓ should not track data usage in (168ms)
      ✓ should not track data usage out (80ms)

  Utility Capabilities
    Omit Utility
      ✓ it should remove properties while maintaing the array
      ✓ it should remove properties while maintaing the object
    Parse Utility
      ✓ it should return a string when given a string
      ✓ it should return an object when given a stringified object
    isJson Utility
      ✓ it should return true for an object
      ✓ it should return true for an empty object
      ✓ it should return true for a stringified object
      ✓ it should return false for a number
      ✓ it should return false for undefined
      ✓ it should return false for a string
      ✓ it should return false for null


  177 passing (48s)

------------------------------|----------|----------|----------|----------|-------------------|
File                          |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
------------------------------|----------|----------|----------|----------|-------------------|
All files                     |      100 |      100 |      100 |      100 |                   |
 fms-api-client               |      100 |      100 |      100 |      100 |                   |
  index.js                    |      100 |      100 |      100 |      100 |                   |
 fms-api-client/src           |      100 |      100 |      100 |      100 |                   |
  index.js                    |      100 |      100 |      100 |      100 |                   |
 fms-api-client/src/models    |      100 |      100 |      100 |      100 |                   |
  agent.model.js              |      100 |      100 |      100 |      100 |                   |
  client.model.js             |      100 |      100 |      100 |      100 |                   |
  connection.model.js         |      100 |      100 |      100 |      100 |                   |
  credentials.model.js        |      100 |      100 |      100 |      100 |                   |
  data.model.js               |      100 |      100 |      100 |      100 |                   |
  index.js                    |      100 |      100 |      100 |      100 |                   |
 fms-api-client/src/services  |      100 |      100 |      100 |      100 |                   |
  container.service.js        |      100 |      100 |      100 |      100 |                   |
  index.js                    |      100 |      100 |      100 |      100 |                   |
  request.service.js          |      100 |      100 |      100 |      100 |                   |
  transform.service.js        |      100 |      100 |      100 |      100 |                   |
 fms-api-client/src/utilities |      100 |      100 |      100 |      100 |                   |
  conversion.utilities.js     |      100 |      100 |      100 |      100 |                   |
  filemaker.utilities.js      |      100 |      100 |      100 |      100 |                   |
  index.js                    |      100 |      100 |      100 |      100 |                   |
------------------------------|----------|----------|----------|----------|-------------------|

Dependencies

  • axios: Promise based HTTP client for the browser and node.js
  • axios-cookiejar-support: Add tough-cookie support to axios.
  • form-data: A library to create readable "multipart/form-data" streams. Can be used to submit forms and file uploads to other web applications.
  • into-stream: Convert a string/promise/array/iterable/buffer/typedarray/arraybuffer/object into a stream
  • lodash: Lodash modular utilities.
  • marpat: A class-based ES6 ODM for Mongo-like databases.
  • mime-types: The ultimate javascript content-type utility.
  • moment: Parse, validate, manipulate, and display dates
  • object-sizeof: Sizeof of a JavaScript object in Bytes
  • prettysize: Convert bytes to other sizes for prettier logging
  • stream-to-array: Concatenate a readable stream's data into a single array
  • tough-cookie: RFC6265 Cookies and Cookie Jar for node.js
  • uuid: RFC4122 (v1, v4, and v5) UUIDs

Dev Dependencies

  • chai: BDD/TDD assertion library for node.js and the browser. Test framework agnostic.
  • chai-as-promised: Extends Chai with assertions about promises.
  • coveralls: takes json-cov output into stdin and POSTs to coveralls.io
  • deep-map: Transforms nested values of complex objects
  • dotenv: Loads environment variables from .env file
  • eslint: An AST-based pattern checker for JavaScript.
  • eslint-config-google: ESLint shareable config for the Google style
  • eslint-config-prettier: Turns off all rules that are unnecessary or might conflict with Prettier.
  • eslint-plugin-prettier: Runs prettier as an eslint rule
  • fs-extra: fs-extra contains methods that aren't included in the vanilla Node.js fs package. Such as mkdir -p, cp -r, and rm -rf.
  • http-proxy: HTTP proxying for the masses
  • jsdoc: An API documentation generator for JavaScript.
  • jsdoc-to-markdown: Generates markdown API documentation from jsdoc annotated source code
  • minami: Clean and minimal JSDoc 3 Template / Theme
  • mocha: simple, flexible, fun test framework
  • mocha-lcov-reporter: LCOV reporter for Mocha
  • mos: A pluggable module that injects content into your markdown files via hidden JavaScript snippets
  • mos-plugin-dependencies: A mos plugin that creates dependencies sections
  • mos-plugin-execute: Mos plugin to inline a process output
  • mos-plugin-installation: A mos plugin for creating installation section
  • mos-plugin-license: A mos plugin for generating a license section
  • mos-plugin-snippet: A mos plugin for embedding snippets from files
  • nyc: the Istanbul command line interface
  • prettier: Prettier is an opinionated code formatter
  • varium: A strict parser and validator of environment config variables

License

MIT © Lui de la Parra

FAQs

Package last updated on 26 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts