
Security News
New CNA Scorecard Tool Ranks CVE Data Quality Across the Ecosystem
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.
fms-api-client
Advanced tools
A FileMaker Data API client designed to allow easier interaction with a FileMaker application from a web environment.
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.
MIT © Lui de la Parra
npm install --save marpat fms-api-client
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 and conventions used by FileMaker wherever possible. The client uses a lightweight datastore to hold Data API connections. For more information about datastore configuration see the datastore connection section and the marpat project.
Each client committed to the datastore will automatically handle Data API Sessions. If required, clients can also 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()
. For more information on Data API Session handling see the Data API sessions section.
All client methods accept parameters as defined by FileMaker. The client also allows for an expanded parameter syntax designed to make interacting with the client easier. Scripts and portals can be defined as arrays. Find queries can be defined as either an object or an array. For more information on the syntax supported by the client see the parameter syntax section.
In addition to the expanded syntax the client will also automatically parse arrays, objects, and numbers to adhere to the requirements of the Data API. The 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 is valid JSON it will be automatically parsed for you by the client.
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.
The client also provides utility modules to aid in working with FileMaker Data API Results. The provided utility modules are fieldData
, recordId
, containerData
, 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 utilities section.
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.
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"
}
]
}
Following the Data API, the prerequest
phase occurs before executing request and sorting of records, the presort
phase after executing request and before sorting records. Not specifying a phase will run the script after the request and sorting are executed.
Note: The FileMaker script and portal syntax will override the alternative scripts and portals syntax.
The custom portals parameter follows the following syntax:
{
"portals": [
{ "name": "planets", "limit": 1, "offset": 1 },
{ "name": "vehicles", "limit": 2 }
]
}
If a portals array is not used all portals on a queried layout will be returned.
Note: The FileMaker script and portal syntax will override the alternative scripts and portals syntax.
Arrays and objects are stringified before being inserted into field or portal data.
{
"data": {
"name": "Yoda",
"Vehicles::name": "The Force"
}
}
Any property not nested in a portalData
property will be moved into the fieldData
property.
The client accepts the same sort parameters as the Data API.
{
"sort": [
{ "fieldName": "name", "sortOrder": "ascend" },
{ "fieldName": "modificationTimestamp", "sortOrder": "descend" }
]
}
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": [
{
"name": "Han solo",
"Vehicles::name": "Millenium Falcon"
},
{
"name": "Luke Skywalker",
"Vehicles::name": "X-Wing Starfighter"
},
{
"age": ">10000"
}
]
}
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
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:
Property | Type | Description |
---|---|---|
application | String | The FileMaker application / database to connect to |
server | String | The FileMaker server to use as the host. Note: Must be an http or https Domain. |
user | String | The FileMaker user account to be used when authenticating into the Data API |
password | String | The FileMaker user account's password. |
[name] | String | A name for the client. |
[usage] | Boolean | Track Data API usage for this client. Note: Default is true |
[timeout] | Number | The default timeout time for requests Note: Default is 0, (no timeout) |
[proxy] | Object | settings for a proxy server |
[agent] | Object | 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.
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"
}
]
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.
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
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
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)
Param | Type | Description |
---|---|---|
layout | String | The layout to use when creating a record. |
data | Object | The data to use when creating a record. |
parameters | Object | The 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"
}
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
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)
Param | Type | Description |
---|---|---|
layout | String | The layout to use when retrieving the record. |
recordId | String | The FileMaker internal record ID to use when retrieving the record. |
parameters | Object | Parameters 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": "https://some-server.com/Streaming_SSL/MainDB/2782DBD000C6F620935073E24634C02297D9EF32BDD29BEEFF6F98EDC9A78D5F?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": ""
},
"portalData": {
"Planets": [],
"Vehicles": []
},
"recordId": "1138",
"modId": "327"
}
]
}
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)
Param | Type | Description |
---|---|---|
layout | String | The layout to use when retrieving the record. |
parameters | Object | the 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/C070AD17B753660A8C3361B4C5E94AFC3717127E40B0692F118D2CA150ED41D7.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"
}
]
}
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)
Param | Type | Description |
---|---|---|
layout | String | The layout to use when performing the find. |
query | Object | to use in the find request. |
parameters | Object | the 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"
}
]
}
The client's edit method requires a layout, recordId, and object to use for updating the record.
client.edit(layout, recordId, data, parameters)
Param | Type | Description |
---|---|---|
layout | String | The layout to use when editing the record. |
recordId | String | The FileMaker internal record ID to use when editing the record. |
data | Object | The data to use when editing a record. |
parameters | Object | parameters 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"
}
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)
Param | Type | Description |
---|---|---|
layout | String | The layout to use when deleting the record. |
recordId | String | The 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:
{}
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)
Param | Type | Description |
---|---|---|
layout | String | The layout to use for the list request |
name | String | The name of the script |
parameters | Object | Parameters 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"
}
}
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)
Param | Type | Description |
---|---|---|
file | String | The path to the file to upload. |
layout | String | The layout to use when performing the find. |
containerFieldName | String | The field name to insert the data into. It must be a container field. |
recordId | Number | String | the recordId to use when uploading the file. |
fieldRepetition | Number | The 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"
}
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"
}
The globals method will set global fields for the current session.
client.globals(data, parameters)
Param | Type | Description |
---|---|---|
data | Object | Array | a 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:
{}
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.
The record id utility retrieves the recordId
properties for a response. This method will return either a single string or an array of strings.
recordId(data)
Param | Type | Description |
---|---|---|
data | Object | Array | the raw data returned from a filemaker. This can be an array or an object. |
const extractRecordIdOriginal = client =>
client
.find('Heroes', { name: 'yoda' }, { limit: 2 })
.then(response => recordId(response.data))
.then(result => log('record-id-utility-example', result));
Excerpt from ./examples/utility.examples.js
original:
[
{
"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"
},
{
"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/record-id-utility-original-example.json
Transformed:
[
"738318",
"738322"
]
The field Data utility retrieves the fieldData
, recordId
, and modId
properties from a Data API response. The field data utility will merge the recordId
and modId
properties into fielData properties. This utility will not convert table::field
properties.
fieldData(data)
Param | Type | Description |
---|---|---|
data | Object | Array | The 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('field-data-utility-example', result));
Excerpt from ./examples/utility.examples.js
Original:
[
{
"fieldData": {
"name": "Yoda",
"image": "https://some-server.com/Streaming_SSL/MainDB/ACFA0ADBE69F55BE557B6FAD33DF385D34E9C5B4440C100CCEEB27C27C4946C2?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": ""
},
"portalData": {
"Planets": [],
"Vehicles": []
},
"recordId": "1138",
"modId": "327"
},
{
"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/field-data-utility-original-example.json
Transformed:
[
{
"name": "Yoda",
"image": "https://some-server.com/Streaming_SSL/MainDB/8DBFEFF953E257F0A90C37DD00A50BC98785D7CF03A6AA7B7EEB44CEE1729D3B?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"
}
]
The transform utility converts Data API response data by converting table::field
properties into objects. This utility will traverse the response data converting { table::field : value}
properties to { table:{ field : value } }
. This 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 properties are convert
,fieldData
,portalData
. The convert
property toggles the transformation of table::field
properties. The fieldData
property toggles merging of fieldData to the result. The portalData
property toggles merging portalData to the result. Setting any property to false will turn that transformation off.
transform(data, parameters)
Param | Type | Description |
---|---|---|
object | Object | The 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
Original:
[
{
"fieldData": {
"starships": "",
"vehicles": "",
"species": "",
"biography": "",
"birthYear": "",
"id": "r2d2-c3po-l3-37-bb-8",
"name": "Han Solo"
},
"portalData": {
"Planets": [
{
"recordId": "1138",
"Planets::name": "Coriella",
"modId": "327"
}
],
"Vehicles": [
{
"recordId": "1138",
"Vehicles::name": "Millenium Falcon",
"Vehicles::type": "Starship",
"modId": "327"
}
]
},
"recordId": "1138",
"modId": "327"
}
]
File ./examples/results/transform-utility-original-example.json
Transformed:
[
{
"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"
}
]
The container data 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.
containerData(data, field, destination, name, parameters)
Param | Type | Description |
---|---|---|
data | Object | Array | The response recieved from the FileMaker DAPI. |
field | String | The container field name to target. This can be a nested property. |
destination | String | "buffer" if a buffer object should be returned or the path to write the file. |
name | String | The field to use for the file name or a static string. |
[parameters] | Object | request parameters. |
[parameters.timeout] | Number | a timeout for the request. |
const getContainerData = client =>
client
.find('Heroes', { imageName: '*' }, { limit: 1 })
.then(result =>
containerData(
result.data,
'fieldData.image',
'./assets',
'fieldData.imageName'
)
)
.then(result => log('container-data-example', result));
Excerpt from ./examples/utility.examples.js
Result:
[
{
"name": "IMG_0001.PNG",
"path": "assets/IMG_0001.PNG"
}
]
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"
}
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.
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.
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.
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.
npm install
npm test
> fms-api-client@1.8.1 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 (243ms)
✓ 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 (226ms)
✓ should automatically recreate an agent if one is deleted (199ms)
Authentication Capabilities
✓ should authenticate into FileMaker. (86ms)
✓ should automatically request an authentication token (171ms)
✓ should reuse a saved authentication token (171ms)
✓ should log out of the filemaker. (168ms)
✓ should not attempt a logout if there is no valid token.
✓ should reject if the logout request fails (166ms)
✓ should reject if the authentication request fails (1515ms)
✓ should attempt to log out before being removed (168ms)
✓ 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 (3228ms)
✓ should download container data from an array to a file (1333ms)
✓ should substitute the record id if a name is not specified (1347ms)
✓ should substitute the record id if a name is not specified (1437ms)
✓ should download container data from an array to a buffer (1472ms)
✓ 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 (1317ms)
✓ should substitute a uuid if the record id can not be found in an array (2277ms)
✓ should reject with an error and a message (245ms)
✓ should reject if the WPE rejects the request (1253ms)
Create Capabilities
✓ should create FileMaker records without fieldData (171ms)
✓ should allow you to specify a timeout
✓ should create FileMaker records using fieldData (86ms)
✓ should create FileMaker records with portalData (82ms)
✓ should allow portalData to be an object or number (83ms)
✓ should reject bad data with an error (81ms)
✓ should create records with mixed types (82ms)
✓ should substitute an empty object if data is not provided (76ms)
✓ should return an object with merged data properties (82ms)
✓ should allow you to run a script when creating a record with a merge response (91ms)
✓ should allow you to specify scripts as an array (95ms)
✓ should allow you to specify scripts as an array with a merge response (91ms)
✓ should sanitize parameters when creating a new record (99ms)
✓ should accept both the default script parameters and a scripts array (91ms)
✓ should remove an expired token (80ms)
Delete Capabilities
✓ should delete FileMaker records. (253ms)
✓ should allow you to specify a timeout (92ms)
✓ should trigger scripts via an array when deleting records. (167ms)
✓ should trigger scripts via parameters when deleting records. (162ms)
✓ should allow you to mix script parameters and scripts array when deleting records. (165ms)
✓ should stringify script parameters. (161ms)
✓ should reject deletions that do not specify a recordId (80ms)
✓ should reject deletions that do not specify an invalid recordId (79ms)
✓ should remove an expired token (82ms)
Edit Capabilities
✓ should edit FileMaker records without fieldData
✓ should allow you to specify a timeout (192ms)
✓ 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 (177ms)
✓ should return an object with merged filemaker and data properties
✓ should allow you to run a script when editing a record (180ms)
✓ should allow you to run a script via a scripts array when editing a record (170ms)
✓ should allow you to specify scripts as an array (177ms)
✓ should allow you to specify scripts as an array with a merge response (169ms)
✓ should sanitize parameters when creating a editing record (170ms)
✓ should accept both the default script parameters and a scripts array (169ms)
✓ should remove an expired token (156ms)
FieldData Capabilities
✓ it should extract field data while maintaining the array (250ms)
✓ it should extract field data while maintaining the object (165ms)
Find Capabilities
✓ should perform a find request (336ms)
✓ should allow you to use an object instead of an array for a find (243ms)
✓ should specify omit Criterea (163ms)
✓ should safely parse omit true and false (155ms)
✓ should allow additional parameters to manipulate the results (80ms)
✓ should allow you to limit the number of portal records to return (75ms)
✓ should allow you to use numbers in the find query parameters (80ms)
✓ should allow you to sort the results (1070ms)
✓ should return an empty array if the find does not return results (87ms)
✓ should allow you run a pre request script (86ms)
✓ should return a response even if a script fails (87ms)
✓ should allow you to send a parameter to the pre request script (87ms)
✓ should allow you run script after the find and before the sort (443ms)
✓ should allow you to pass a parameter to a script after the find and before the sort (456ms)
✓ should reject of there is an issue with the find request (82ms)
✓ should remove an expired token (78ms)
Get Capabilities
✓ should get specific FileMaker records. (253ms)
✓ should allow you to specify a timeout (88ms)
✓ should reject get requests that do not specify a recordId (157ms)
✓ should allow you to limit the number of portal records to return (160ms)
✓ should accept namespaced portal limit and offset parameters (155ms)
✓ should remove an expired token (77ms)
Global Capabilities
✓ should allow you to set session globals (166ms)
✓ should allow you to specify a timeout
✓ should reject with a message and code if it fails to set a global (82ms)
✓ should remove an expired token (77ms)
Request Interceptor Capabilities
✓ should reject if the server errors (146ms)
✓ should handle non JSON responses by rejecting with a json error (118ms)
✓ should reject non http requests to the server with a json error
✓ should reject non https requests to the server with a json error (126ms)
List Capabilities
✓ should allow you to list records (326ms)
✓ should allow you to specify a timeout
✓ should allow you use parameters to modify the list response (76ms)
✓ should should allow you to use numbers in parameters (76ms)
✓ should should allow you to provide an array of portals in parameters (80ms)
✓ should should remove non used properties from a portal object (80ms)
✓ should modify requests to comply with DAPI name reservations (82ms)
✓ should allow strings while complying with DAPI name reservations (74ms)
✓ should allow you to offset the list response (81ms)
✓ should santize parameters that would cause unexpected parameters (79ms)
✓ should allow you to limit the number of portal records to return (81ms)
✓ should accept namespaced portal limit and offset parameters (83ms)
✓ should reject invalid parameters (81ms)
✓ should remove an expired token (77ms)
RecordId Capabilities
✓ it should extract the recordId while maintaining the array (249ms)
✓ it should extract recordId while maintaining the object (159ms)
Script Capabilities
✓ should allow you to trigger a script (181ms)
✓ should allow you to specify a timeout
✓ should allow you to trigger a script specifying a string as a parameter (80ms)
✓ should allow you to trigger a script specifying a number as a parameter (81ms)
✓ should allow you to trigger a script specifying an object as a parameter (84ms)
✓ should allow you to trigger a script in a find (242ms)
✓ should allow you to trigger a script in a list (85ms)
✓ should reject a script that does not exist (76ms)
✓ should allow return a result even if a script returns an error (88ms)
✓ should parse script results if the results are json (82ms)
✓ should not parse script results if the results are not json (82ms)
✓ should parse an array of scripts (93ms)
✓ should trigger scripts on all three script phases (96ms)
✓ should remove an expired token (77ms)
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 (343ms)
✓ should merge portal data and field data from an object (147ms)
✓ should optionally not convert table::field keys from an array (140ms)
✓ should optionally not convert table::field keys from an object (150ms)
✓ should allow you to remove field data from an array (188ms)
✓ should allow you to remove field data from an object (147ms)
✓ should allow you to remove portal data from an array (150ms)
✓ should allow you to remove portal data from an object (143ms)
✓ should merge portal data and portal data from an array (151ms)
File Upload Capabilities
✓ should allow you to specify a timeout (181ms)
✓ should allow you to upload a file to a new record (1356ms)
✓ should allow you to upload a buffer to a new record (1536ms)
✓ should allow you to upload a file to a specific container repetition (1270ms)
✓ should allow you to upload a buffer to a specific container repetition (1495ms)
✓ 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 (1256ms)
✓ should allow you to upload a buffer object to a specific record (1262ms)
✓ should allow you to upload a file to a specific record container repetition (1249ms)
✓ should allow you to upload a buffer to a specific record container repetition (1452ms)
✓ should reject of the request is invalid (230ms)
✓ should reject an empty buffer object (80ms)
✓ should reject a null buffer object (79ms)
✓ should reject a number instead of an object (79ms)
✓ should reject an object without a filename (82ms)
✓ should reject an object without a buffer (91ms)
✓ should remove an expired token (85ms)
Data Usage
Tracks Data Usage
✓ should track API usage data. (166ms)
✓ should allow you to reset usage data. (81ms)
Does Not Track Data Usage
✓ should not track data usage in (168ms)
✓ should not track data usage out (83ms)
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 (46s)
------------------------------|----------|----------|----------|----------|-------------------|
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 | |
------------------------------|----------|----------|----------|----------|-------------------|
FAQs
A FileMaker Data API client designed to allow easier interaction with a FileMaker database from a web environment.
The npm package fms-api-client receives a total of 37 weekly downloads. As such, fms-api-client popularity was classified as not popular.
We found that fms-api-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.