@jd-data-limited/easy-fm 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.idea/easy-fm.iml CHANGED
@@ -1,8 +1,8 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$" />
5
- <orderEntry type="inheritedJdk" />
6
- <orderEntry type="sourceFolder" forTests="false" />
7
- </component>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="inheritedJdk" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ </component>
8
8
  </module>
package/.idea/modules.xml CHANGED
@@ -1,8 +1,8 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/easy-fm.iml" filepath="$PROJECT_DIR$/.idea/easy-fm.iml" />
6
- </modules>
7
- </component>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/easy-fm.iml" filepath="$PROJECT_DIR$/.idea/easy-fm.iml" />
6
+ </modules>
7
+ </component>
8
8
  </project>
package/.idea/php.xml ADDED
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="MessDetectorOptionsConfiguration">
4
+ <option name="transferred" value="true" />
5
+ </component>
6
+ <component name="PHPCSFixerOptionsConfiguration">
7
+ <option name="transferred" value="true" />
8
+ </component>
9
+ <component name="PHPCodeSnifferOptionsConfiguration">
10
+ <option name="transferred" value="true" />
11
+ </component>
12
+ <component name="PhpStanOptionsConfiguration">
13
+ <option name="transferred" value="true" />
14
+ </component>
15
+ <component name="PsalmOptionsConfiguration">
16
+ <option name="transferred" value="true" />
17
+ </component>
18
+ </project>
package/.idea/vcs.xml CHANGED
@@ -1,6 +1,6 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
6
  </project>
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 JD-Data-Limited
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 JD-Data-Limited
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,193 +1,212 @@
1
- # easy-fm
2
-
3
- easy-fm is a Node.js module that allows you to interact with
4
- a [FileMaker database](https://www.claris.com/filemaker/) stored on
5
- a [FileMaker server](https://www.claris.com/filemaker/server/). This module interacts with your server using the
6
- [FileMaker Data API](https://help.claris.com/en/data-api-guide/content/index.html).
7
-
8
- ## FileMaker setup instructions
9
-
10
- 1. Enable the FileMaker Data API from the server's admin console. This setting is located
11
- in `Connectors > FileMaker Data API`.
12
- 2. Create a FileMaker database account for easy-fm to use. This account must have the 'Access via FileMaker Data API (
13
- fmrest)' extended privilege
14
-
15
- ## Table of contents
16
-
17
- 1. [Connecting to a database](#connecting-to-a-database)
18
- 2. [Working with records](#working-with-records)
19
- 3. [Performing find requests](#perform-find-requests)
20
- 4. [Scripts](#scripts)
21
- 5. [Index](#index)
22
-
23
- ## Connecting to a database
24
-
25
- easy-fm currently does not support connecting to external data sources, or authenticating by any method other than plain
26
- FileMaker authentication.
27
-
28
- ```javascript
29
- import fm, {FMError} from "easy-fm"; // Import the module
30
- const connection = new fm(); // This variable will be used for interacting with the server
31
-
32
- connection.login(hostname, database, username, password).then(async token => { // Login
33
-
34
- })
35
- ```
36
-
37
- ## Working with records
38
-
39
- When running scripts or interacting with records, the first step that you need to do is get the layout that you want to
40
- use
41
-
42
- ```javascript
43
- let layout = connection.getLayout("layout1") // Get the layout known as 'layout1'
44
- ```
45
-
46
- Once you have the layout, you can perform a multitude of tasks
47
-
48
- ### Get a single record using its RecordID
49
-
50
- [What's a RecordID?](#recordid)
51
-
52
- ```javascript
53
- let record_id = 1
54
- let record = layout.getRecord(record_id)
55
-
56
- await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
57
-
58
- let field = record.getField("field1")
59
- console.log(field.value) // Get the value of 'field1'
60
- ```
61
-
62
- ### Modify a record
63
-
64
- WARNING: The commit step is mandatory. Otherwise the changes will never be uploaded
65
-
66
- ```javascript
67
- let record_id = 1
68
- let record = layout.getRecord(record_id)
69
-
70
- await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
71
- record.getField("field1").set("This is a value")
72
- record.getField("field2").set("This is also a value")
73
- await record.commit()
74
- ```
75
-
76
- ### Create a new record
77
-
78
- WARNING: The record is not created on the database until a commit is done
79
-
80
- ```javascript
81
- let record = await layout.createRecord()
82
- record.getField("field1").set("ABC")
83
- record.getField("field2").set("DEF")
84
- await record.commit()
85
- ```
86
-
87
- ### Downloading container field files
88
-
89
- ```javascript
90
- let record_id = 1
91
- let record = layout.getRecord(record_id)
92
-
93
- await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
94
-
95
- let container = record.getField("container")
96
- container.download().then(stream => {
97
- // Returns an IncomingMessage, which is an extension of ReadableStream
98
- })
99
- ```
100
-
101
- [IncomingMessage](https://nodejs.org/api/http.html#class-httpincomingmessage)
102
- , [ReadableStream](https://nodejs.org/api/stream.html#class-streamreadable)
103
-
104
- ### Uploading container files
105
-
106
- When uploading files, they should be uploaded as a [Buffer](https://nodejs.org/api/buffer.html) object, along with a
107
- filename (string) and MIME (also string)
108
-
109
- MIME types are not currently automatically detected
110
-
111
- ```javascript
112
- const fs = require("fs")
113
- let filename = "image.jpg"
114
- let buffer = fs.readdirSync("./" + filename)
115
- let mime = "image/jpeg"
116
-
117
- let record_id = 1
118
- let record = layout.getRecord(record_id)
119
- await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
120
-
121
- let container = record.getField("container")
122
- container.upload(buffer, filename, mime).then(() => {
123
- console.log("UPLOAD SUCCESSFUL!")
124
- })
125
- ```
126
- [(Mozilla) Common MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types)
127
-
128
- ### Read and modify portal information
129
-
130
- To be able to read portal information for a record, you'll need to put a portal on the layout you are using. Make sure
131
- you also:
132
-
133
- - Give the portal object a name
134
- - Include the exact fields you need in the portal. Any fields you leave out will not be accessible by node.js, and
135
- putting extra fields in is not a good idea.
136
-
137
- ```javascript
138
- let record = layout.getRecord(1)
139
-
140
- // Portal data is downloaded when the record is fetched
141
- await record.get()
142
- let portal = record.getPortal("Portal1")
143
-
144
- for (let _record of portal.records) {
145
- // Runs for all records in the portal
146
- let field = _record.getField("field2")
147
- console.log(field.value)
148
- field.set("GHI")
149
- }
150
- ```
151
-
152
- **WARNING**: Commiting a related portal record will also commit any changes to the parent record as well as any other
153
- portal records.
154
-
155
- ## Perform find requests
156
-
157
- Performing find requests is one of the most common database operations
158
-
159
- ![img.png](img.png)
160
-
161
- The image above is how the find request would look when doing it in a FileMaker script. This should hopefully help you
162
- understand how the find request process works.
163
-
164
- ```javascript
165
- let find = layout.newFind() // Create a new find operation
166
-
167
- find.addRequests( // Specify the find criteria
168
- {"PrimaryKey": "AAAAA", "ModifiedBy": "BBBB"},
169
- {"CreatedBy": "BBBB"}
170
- )
171
-
172
- find.addSort("CreatedBy", "ascend") // Sort the results in ascending order
173
- let records = await find.find() // Perform the find
174
- console.log(records)
175
- ```
176
-
177
- ### Scripts
178
-
179
- Running scripts is another operation you may need to do regularly. This one is fairly straight-forward in how it works
180
-
181
- ```javascript
182
- let layout = connection.getLayout("layout1")
183
- let script = connection.script("MyFileMakerScript", "This is a parameter")
184
- let result = await layout.runScript(script)
185
- console.log(result)
186
- ```
187
-
188
- ## Index
189
-
190
- ### RecordID
191
-
192
- This is not a custom field that can be set and/or changed. You can get a record's ID from within FileMaker by
1
+ # easy-fm
2
+
3
+ easy-fm is a Node.js module that allows you to interact with
4
+ a [FileMaker database](https://www.claris.com/filemaker/) stored on
5
+ a [FileMaker server](https://www.claris.com/filemaker/server/). This module interacts with your server using the
6
+ [FileMaker Data API](https://help.claris.com/en/data-api-guide/content/index.html).
7
+
8
+ ## FileMaker setup instructions
9
+
10
+ 1. Enable the FileMaker Data API from the server's admin console. This setting is located
11
+ in `Connectors > FileMaker Data API`.
12
+ 2. Create a FileMaker database account for easy-fm to use. This account must have the 'Access via FileMaker Data API (
13
+ fmrest)' extended privilege
14
+
15
+ ---
16
+
17
+ ## Table of contents
18
+
19
+ 1. [Connecting to a database](#connecting-to-a-database)
20
+ 2. [Working with records](#working-with-records)
21
+ 3. [Performing find requests](#perform-find-requests)
22
+ 4. [Scripts](#scripts)
23
+ 5. [Index](#index)
24
+
25
+ ---
26
+
27
+ ## Connecting to a database
28
+
29
+ easy-fm currently does not support connecting to external data sources, or authenticating by any method other than plain
30
+ FileMaker authentication.
31
+
32
+ ```javascript
33
+ import fm, {FMError} from "easy-fm"; // Import the module
34
+ const connection = new fm(); // This variable will be used for interacting with the server
35
+
36
+ connection.login(hostname, database, username, password).then(async token => { // Login
37
+
38
+ })
39
+ ```
40
+
41
+ ---
42
+
43
+ ## Working with records
44
+
45
+ When running scripts or interacting with records, the first step that you need to do is get the layout that you want to
46
+ use
47
+
48
+ ```javascript
49
+ let layout = connection.getLayout("layout1") // Get the layout known as 'layout1'
50
+ ```
51
+
52
+ Once you have the layout, you can perform a multitude of tasks
53
+
54
+ ### Get a single record using its RecordID
55
+
56
+ [What's a RecordID?](#recordid)
57
+
58
+ ```javascript
59
+ let record_id = 1
60
+ let record = layout.getRecord(record_id)
61
+
62
+ await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
63
+
64
+ let field = record.getField("field1")
65
+ console.log(field.value) // Get the value of 'field1'
66
+ ```
67
+
68
+ ### Modify a record
69
+
70
+ WARNING: The commit step is mandatory. Otherwise the changes will never be uploaded
71
+
72
+ ```javascript
73
+ let record_id = 1
74
+ let record = layout.getRecord(record_id)
75
+
76
+ await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
77
+ record.getField("field1").set("This is a value")
78
+ record.getField("field2").set("This is also a value")
79
+ await record.commit()
80
+ ```
81
+
82
+ ### Create a new record
83
+
84
+ WARNING: The record is not created on the database until a commit is done
85
+
86
+ ```javascript
87
+ let record = await layout.createRecord()
88
+ record.getField("field1").set("ABC")
89
+ record.getField("field2").set("DEF")
90
+ await record.commit()
91
+ ```
92
+
93
+ ### Downloading container field files
94
+
95
+ ```javascript
96
+ let record_id = 1
97
+ let record = layout.getRecord(record_id)
98
+
99
+ await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
100
+
101
+ let container = record.getField("container")
102
+ container.download().then(stream => {
103
+ // Returns an IncomingMessage, which is an extension of ReadableStream
104
+ })
105
+ ```
106
+
107
+ [IncomingMessage](https://nodejs.org/api/http.html#class-httpincomingmessage)
108
+ , [ReadableStream](https://nodejs.org/api/stream.html#class-streamreadable)
109
+
110
+ ### Uploading container files
111
+
112
+ When uploading files, they should be uploaded as a [Buffer](https://nodejs.org/api/buffer.html) object, along with a
113
+ filename (string) and MIME (also string)
114
+
115
+ MIME types are not currently automatically detected
116
+
117
+ ```javascript
118
+ const fs = require("fs")
119
+ let filename = "image.jpg"
120
+ let buffer = fs.readdirSync("./" + filename)
121
+ let mime = "image/jpeg"
122
+
123
+ let record_id = 1
124
+ let record = layout.getRecord(record_id)
125
+ await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
126
+
127
+ let container = record.getField("container")
128
+ container.upload(buffer, filename, mime).then(() => {
129
+ console.log("UPLOAD SUCCESSFUL!")
130
+ })
131
+ ```
132
+ [(Mozilla) Common MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types)
133
+
134
+ ### Read and modify portal information
135
+
136
+ To be able to read portal information for a record, you'll need to put a portal on the layout you are using. Make sure
137
+ you also:
138
+
139
+ - Give the portal object a name
140
+ - Include the exact fields you need in the portal. Any fields you leave out will not be accessible by node.js, and
141
+ putting extra fields in is not a good idea.
142
+
143
+ ```javascript
144
+ let record = layout.getRecord(1)
145
+
146
+ // Portal data is downloaded when the record is fetched
147
+ await record.get()
148
+ let portal = record.getPortal("Portal1")
149
+
150
+ for (let _record of portal.records) {
151
+ // Runs for all records in the portal
152
+ let field = _record.getField("field2")
153
+ console.log(field.value)
154
+ field.set("GHI")
155
+ }
156
+ ```
157
+
158
+ **WARNING**: Commiting a related portal record will also commit any changes to the parent record as well as any other
159
+ portal records.
160
+
161
+ ---
162
+
163
+ ## Perform find requests
164
+
165
+ Performing find requests is one of the most common database operations
166
+
167
+ ![img.png](img.png)
168
+
169
+ The image above is how the find request would look when doing it in a FileMaker script. This should hopefully help you
170
+ understand how the find request process works.
171
+
172
+ ```javascript
173
+ let find = layout.newFind() // Create a new find operation
174
+
175
+ find.addRequests( // Specify the find criteria
176
+ {"PrimaryKey": "AAAAA", "ModifiedBy": "BBBB"},
177
+ {"CreatedBy": "BBBB"}
178
+ )
179
+
180
+ find.addSort("CreatedBy", "ascend") // Sort the results in ascending order
181
+ let records = await find.find() // Perform the find
182
+ console.log(records)
183
+ ```
184
+
185
+ ---
186
+
187
+ ### Scripts
188
+
189
+ Running scripts is another operation you may need to do regularly. This one is fairly straight-forward in how it works
190
+
191
+ ```javascript
192
+ let layout = connection.getLayout("layout1")
193
+ let script = connection.script("MyFileMakerScript", "This is a parameter")
194
+ let result = await layout.runScript(script)
195
+ console.log(result)
196
+ ```
197
+
198
+ ---
199
+
200
+ ## Classes and methods
201
+
202
+
203
+
204
+
205
+ ---
206
+
207
+ ## Index
208
+
209
+ ### RecordID
210
+
211
+ This is not a custom field that can be set and/or changed. You can get a record's ID from within FileMaker by
193
212
  using `Get(RecordID)`
package/decs.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- declare module "fs"
2
- declare module "events"
3
- declare module "path"
4
- declare module "url"
5
- declare module "node-fetch"
6
- declare module "btoa"
1
+ declare module "fs"
2
+ declare module "events"
3
+ declare module "path"
4
+ declare module "url"
5
+ declare module "node-fetch"
6
+ declare module "btoa"
7
7
  declare module "buffer"
@@ -0,0 +1,86 @@
1
+ # Class: FileMakerConnection
2
+
3
+ ## Constructor
4
+
5
+ ```javascript
6
+ export default class FileMakerConnection {
7
+ public hostname: string;
8
+ public database: string;
9
+ public token: any;
10
+ private username: any;
11
+ private password: any;
12
+ private rejectUnauthroized: boolean;
13
+
14
+ constructor() {
15
+ }
16
+ }
17
+ ```
18
+
19
+ This is the primary class as it holds information about the FileMaker connection
20
+
21
+ ## Methods
22
+
23
+ ### login(hostname, database, username, password, rejectUnauthorised)
24
+
25
+ Creates a new login session on the FileMaker server, using the specified account.
26
+
27
+ #### Parameters
28
+
29
+ | Parameter | Optional? | Default | Supported types |
30
+ |--------------------|-----------|---------|-----------------|
31
+ | hostname | No | N/A | string |
32
+ | database | No | N/A | string |
33
+ | username | No | N/A | string |
34
+ | password | No | N/A | string |
35
+ | rejectUnauthorised | Yes | true | boolean |
36
+
37
+ #### Returns:
38
+
39
+ Promise &lt;token&gt;
40
+
41
+ ### importSession(token, rejectUnauthorised)
42
+
43
+ Allows you to import and use a FileMaker Data API token that was generated in another application.
44
+
45
+ #### Parameters
46
+
47
+ | Parameter | Optional? | Default | Supported types |
48
+ |--------------------|-----------|---------|-----------------|
49
+ | token | No | N/A | string |
50
+ | rejectUnauthorised | Yes | true | boolean |
51
+
52
+ #### Returns:
53
+
54
+ Promise &lt;void&gt;
55
+
56
+ ### getLayout(name)
57
+
58
+ #### Parameters
59
+
60
+ | Parameter | Optional? | Default | Supported types | Description |
61
+ |--------------------|-----------|---------|-----------------|-------------------------------------------|
62
+ | name | No | N/A | string | The name of the layout you wish to access |
63
+
64
+ #### Returns:
65
+
66
+ [layout](layout.md)
67
+
68
+ ### apiRequest(name)
69
+
70
+ #### Parameters
71
+
72
+ | Parameter | Optional? | Default | Supported types | Description |
73
+ |--------------------|-----------|---------|-----------------|-------------------------------------------|
74
+ | name | No | N/A | string | The name of the layout you wish to access |
75
+
76
+ #### Returns:
77
+
78
+ [layout](layout.md)
79
+
80
+ ### logout()
81
+
82
+ Ends the current database session
83
+
84
+ #### Returns:
85
+
86
+ Promise &lt;void&gt;
File without changes