UNPKG

35.3 kBMarkdownView Raw
1# README #
2
3# sri-client #
4
5* this is the project with all kind of utilities for clients which are using A [sri4node][sri4node-project] API.
6* version 2.3.2
7
8## sri-clients ##
9The project contains three client modules with all kind of functions to do API requests according to [SRI (Standard ROA Interface)][sri-documentation]:
10
11* ng-sri-client: an Angular 1 module
12* node-fetch: a node module on the node version of fetch
13* fetch-sri-client: a module on browser fetch
14
15They both have the same generic interface
16
17### generic interface ###
18
19* **getRaw(href, parameters, options):** http get of the href with the given parameters. Returns a promise with the exact result from the api.
20* **get(href, parameters, options):** http get a single resource with the given href and the parameters. Returns a promise with the resource.
21* **getList(href, parameters, options):** http get of the href with the given parameters where href is suposed to be a list resource.
22Returns a promise with the array of the expanded results that match the query (so not an object with an href and $$expanded, but the object that is $$expanded.
23The list of results is limited to only one API call so the lenght will be maximum the limit. The resulting array will also have properties count and next from the original $$meta section.
24* **getAll(href, parameters, options):** http get of the href with the given parameters where href is suposed to be a list resource.
25Returns a promise with the array of the expanded results that match the query (so not an object with an href and $$expanded, but the object that is $$expanded.
26The list of results is all the results that match the query, because the next links are requested as well and concatenated to the result.
27The resulting array will also have properties count and next from the original $$meta section.
28* **put(href, payload, options):** http put to href with the given payload.
29* **patch(href, payload, options):** http patch to href with the given payload.
30* **updateResource(resource, options):** http put to resource.$$meta.permalink with resource as payload. Compact function to do an update of an existing resource.
31* **post(href, payload, options):** http post to href with the given payload.
32* **delete(href, options):** http delete to href.
33* **getAllHrefs(hrefs, parameters, options):** returns an array of all objects for hrefs, a given array with permalinks.
34* ~~**getAllHrefs(hrefs, batchHref, parameters, options):** returns an array of all objects for hrefs, a given array with permalinks.
35All these parameters need to be of the same resource type! You can provide expansion (or other) parameters with parameters.
36It will get all these permalinks in the most efficient way if an href to the corresponding batch url is provided.
37If the batch url is null it will get them in individual request in groups of 100 (can be overwritten with options.groupBy) permalinks in order to not make the request url too long.~~ (deprecated: use inBatch option)
38* **getAllReferencesTo(baseHref, params, referencingParameterName, hrefsArray, options):** Same as getAll but you can add a referencingParameterName and an array of hrefs.
39It will add referencingParameterName as a parameter and add the hrefsArray as a comma separated string,
40but it will only request them in groups of 100 (can be overwritten with options.groupBy) to make sure the request url does not get too long.
41If the name of the resource is too long you might have to use options.groupBy to decrease the number of hrefs it groups in one request
42
43All these methods return a promise. If the response status >= 400, the result will return an error object with:
44
45* **status:** the http status of the response, null if there was no response.
46* **body:** the body of the response if it was present.
47* **getResponseHeader(headerName):** method that returns the value of the given headerName of the response.
48
49If the result of put, updateResouce or post was < 300 the promise returns an object with:
50
51* **getResponseHeader(headerName):** method that returns the value of the given headerName of the response.
52
53All methods have an **options** object that you can pass on as a parameter. You can specify the following properties:
54
55* **common**
56 * **baseUrl:** sends the http request to this baseUrl instead of the default baseUrl that is set in the initialisation of the configuration.
57 * **headers:** An object with headers that are added on the http request. f.e.: {'foo': 'bar'} adds a header foo with value bar.
58 * **retry:** An object wih retry configuration for doing retries with exponential backoff strategy. Retries will not be done for http status code 4xx.
59 * retries: [required] number of retries you want to do. If retries === 1 => it will only try once again, so two times in total.
60 * initialWait: initial number of miliseconds to wait after the initial GET failed and before the first retry is done. The default is 500 miliseconds.
61 * factor: Strategy is exponential backoff so by default with 4 retries you will wait 0,5s, then 1s, then 2s and then 4s. If you set factor to 3 for instance the time to wait will be multiplied with 3 instead of two so you will wait 0,5s -> 1,5s -> 4,5s -> 13,5s. If you set factor to 1, you will actually disable exponential backoff.
62 * **caching:** An object with properties timeout (in seconds) which overwrites the default timeout (you don't need to set up default caching, you can just start caching several requests). The resource will be get from the cache if it it is not older than the timeout in seconds.
63 * **inBatch:** Specify the href where the batch needs to be send to. This is for GET methods (getAll, getList, etc.) and wraps the regular request into a batch request. This can be usefull when their is a potential of an request url that becomes too long.
64 * **batchMethod:** if batchMethod is 'POST' the inBatch request will be done with A POST instead of A PUT.
65 * **keepBatchAlive:** Only possible for requests to /batch. Handles the batch in a streaming way keeping the connection open so the server does not decide to break off the request (Heroku for example breaks off requests after 30s). This does not mean that you get your response in a streaming way. The response is the same for the client as a regular /batch.
66 * **expand:** array with property paths that you want to expand client side. You can expand as deep as you want and don't need to add $$expanded to the path. See the examples.
67 You can also replace a property path string with an object to pass on more advanced options. The object contains the following proerties:
68 * property: [required] the property path.
69 * required: default is true. If true an error will be thrown if a property in the property path can not be found. This is to help the user detect typo's.
70 If required is false, no error will be thrown and expansion will be ignored for objects that do not have a property in the property path. If the property path contains properties that are not required you need to set this proeprty to false.
71 * include: you can include resources within the expanded resources. Works the same as the include property on the root of the options.
72 * caching: overwrite the caching options from this point onwards. For example when you can not cache the resource you are getting but the resources that are expanded can be cached for a very long time.
73 Example: api.getAll('/responsibilities/relations', {to: #{an href to a responsibility}}, {expand: [from.organisationalunit]}) expands in two steps first all froms in the resultset, and in a second step all organisationalunits of those froms.
74 * **include:** array of objects with configuration to include a property of the/all resrouce(s) (in the resultset). The configuration can contain the following properties:
75 * alias: [required] An {{alias}} property will be added to the resource or every resource in the resultset if it is a list. It is recommended to add a $$ prefix in front of them so the client will not send this back to the server on PUT.
76 * href: [required] The href on which the included resources can be found
77 * reference: an object with the following properties:
78 * property: [required] The property name that references $$meta.permalink of the resource for which you are including resources
79 * parameterName: This is the parameter name on the href to reference the $$meta.permalink of the resource you are including resources.
80 If not added the property name will be taken as parameter name because in many cases this is the same. There is also a short notation where the value of reference is just the property name as a string instead of an object.
81 * filters: filter on the resources you are including (for example include only external identifiers of type INSTITUTION_NUMBER when you are including external identifiers in an organisational unit)
82 * expanded: true is default so you don't need to add this property if true. If false all results will be unexpanded and you will get only the hrefs
83 * singleton: false is default so you don't need to add this property if false. The value of '$${{alias}}' will be an object (the first object in the resultset) instead of an array. It will be null if there are no results.
84 * expand: client side expansion of properties within the included resources. Works the same as the expand property on the root of the options.
85 * include: include resources within the included resources. This is just recursive and works the same as the include property on the root of the options.
86 * **limit:** return a limited number of results for getList, the limit can also be higher than the maximum limit that the server allows. =TODO
87 * **raw:** boolean that can be used for getList and getAll. If set to true the array of results will contain the raw result of the body.results, so the items will be an object with an href and a $$expanded object.
88 * **asMap:** boolean that can be used for getAllHrefs. If set to true an object with be returned which contains all the hrefs as keys and the object to which it refers as value.
89* **fetch-sri-client**
90 * **cancel**: A promise that will cancel the request when resolved
91 * **cache**: See [here][fetch-cache-options] for possible options. Default is 'default'
92 * **credentials**: omit (default) || include (adds the cookies to the request)
93 * **fullResponse**: the response will be an object with properties body and headers
94* **node-fetch / node-sri-client**
95 * **fullResponse**: the response will be an object with properties body and headers
96 * **username**: username for basic authentication
97 * **password**: password for basic authentication
98 * **timeout**: req/res timeout in ms, it resets on redirect. 0 to disable (OS limit applies).
99* **ng-sri-client specific**
100 * **raw** default is false. The response will be parsed. If raw is true the response will not be parsed.
101 * **cancelPromise:** A promise that will cancel the request, if it gets resolved.
102 * **pending:** boolean that will be set to true by every method when the request starts and set to false once the result is fetched.
103
104#### examples ####
105
106```javascript
107 const respsOfTeam = await sriClient.getAll('/responsibilities', {organisationalUnit: '/organisationalunits/eb745d58-b818-4569-a06e-68733fe2e5b3'}, {logging: 'debug'});
108 const personHrefs = respsOfTeam.map(resp => resp.person.href);
109 const persons = await vskoApi.getAllHrefs(personHrefs, '/persons/batch', undefined, {asMap: true});
110 // persons is a map with as key the href of a person and as value the resource of that person.
111
112 const externalIdentifierWithOrganisationalUnitExpanded = await sriClient.get(
113 '/organisationalunits/externalidentifiers',
114 {value: '032557'},
115 {
116 expand: [
117 'organisationalUnit.$$contactDetails.phone.organisationalUnit', // this is circular so not very usefull, but this shows you can expand as deep as you want to
118 'organisationalUnit.$$contactDetails.email'
119 ]
120 });
121
122 const organisationalUnitWithInstitutionNumberIncluded = await sriClient.get('/organisationalunits/a2c36c96-a3a4-11e3-ace8-005056872b95', undefined, {include: {
123 alias: '$$institutionNumber',
124 href: '/organisationalunits/externalidentifiers',
125 filters: {type: 'INSTITUTION_NUMBER'},
126 reference: 'organisationalUnit',
127 singleton: true
128 }});
129
130 const personWithResponsibilitiesIncluded = await sriClient.get('/persons/94417de5-840c-4df4-a10d-fe30683d99e1', undefined, {include: {
131 alias: '$$responsibilities',
132 href: '/responsibilities',
133 reference: {
134 property: 'person',
135 parameterName: 'personIn'
136 },
137 expand: ['organisationalUnit']
138 }});
139
140 // give all the responsibilies of an organisationalunit (this is the team)
141 // and expand the person (client side).
142 // Include for this person all his responsibilities
143 // and expand the organisationalunits of these responsibilities
144 sriClient.getAll('/responsibilies',
145 {
146 organisationalunit: '/organisationalunits/eb745d58-b818-4569-a06e-68733fe2e5b3',
147 expand: 'position' // expand position server side
148 },
149 {
150 expand: [{
151 property: 'person', // expand all person properties client side,
152 required: false,
153 include: [{
154 alias: '$$responsibilities', // A $$responsibilities property will be added to every resource in the resultset
155 href: '/responsibilities',
156 reference: {
157 property: 'person',
158 parameterName: 'personIn',
159 }
160 expand: ['organisationalUnit'], // client side expansion of properties within the included resources
161 }]
162 }]
163 }
164 );
165 // for each responsibility in the resultset, the expanded person will have an added property $$responsibilities,
166 // which is an array of all the responsibilities that reference this person.
167 // Within these last responsibilities the organisationalUnit will be expanded
168 ```
169
170
171### initialisation ###
172
173It is recommended to initialise the library with some default configuration which can have te following properties:
174
175* baseUrl: the default baseUrl for all the api calls.
176* logging: For every request logs the response body if the status code >= 400 to the console for any value. Any value always logs errors. Otherwise you can add a string containing values: 'get','put','post','delete','caching','expand'.
177* caching: object with properties
178 * timeout: default timeout in seconds that will be used for every call that does not specify it's own caching in the options (default is 0 = no caching)
179 * maxSize: maximum size of the cache in MB. When this size is reached the 25% of the hrefs that were not used for the longest time will be removed from the cache. (default is 10MB)
180 * initialisation: array of objects
181 * hrefs: array of hrefs that should be called
182 * timeout: optional timeout that these initial hrefs should be cached. If not mentioned the default timeout above will be taken.
183
184and the following properties are for the node-sri-client only:
185
186* username: username for basic authentication calls.
187* password: password for basic authentication calls.
188* headers: each request will have the headers specified added in the request header.
189* accessToken: an object with properties name and value. Each request will have a request header added with the given name and value. This is added to the headers if they are specified.
190
191#### fetch-sri-client ####
192
193This module uses the Fetch API.
194Here is an example how to use the module.
195
196```javascript
197const configuration = {
198 baseUrl: 'https://api.katholiekonderwijs.vlaanderen',
199 caching: {
200 timeout: 400,
201 initialise: [{
202 timeout: 10000,
203 hrefs: ['/commons/cities', '/commons/countries']
204 ]
205 }
206}
207
208const api = require('@kathondvla/sri-client/fetch-sri-client')(configuration)
209
210let secondarySchools = await api.get('/schools', {educationLevels: 'SECUNDAIR'});
211```
212
213#### ng-sri-client ####
214
215```javascript
216const basicConfig = const configuration = {
217 name: 'api',
218 baseUrl: 'https://api.katholiekonderwijs.vlaanderen'
219}
220
221const fastlyConfig = const configuration = {
222 name: 'cachedApi',
223 baseUrl: 'https://fastly-api.be'
224}
225
226
227// if you only need one version of an API you can just pass on an object as an argument instead of an array: require('@kathondvla/sri-client/ng-sri-client')(basicConfig]);
228const app = angular.module('MyApp', [require('@kathondvla/sri-client/ng-sri-client')([basicConfig, fastlyConfig])]);
229
230//inside a component
231
232['api', 'cachedApi', function (api, cachedApi) {
233 let secondarySchools = await api.get('/schools', {educationLevels: 'SECUNDAIR'});
234 let cities = await cachedApi.getAll('/cities');
235}];
236```
237#### node-sri-client ####
238
239This module is build upon [requestretry][npm-requestretry] which itself is build upon [request][npm-request].
240Here is an example how to use the module.
241
242```javascript
243const configuration = {
244 baseUrl: 'https://api.katholiekonderwijs.vlaanderen',
245 username: 'foo',
246 password: 'bar',
247 caching: {
248 timeout: 400,
249 initialise: [{
250 timeout: 10000,
251 hrefs: ['/commons/cities', '/commons/countries']
252 ]
253 }
254}
255
256const api = require('@kathondvla/sri-client/node-sri-client')(configuration)
257
258let secondarySchools = await api.get('/schools', {educationLevels: 'SECUNDAIR'});
259```
260
261### caching ###
262
263There is always a cache assigned to the client. If no configuration is added the timout will be 0 and the maxSize is null.
264The default timeout can be overwritten by both the get method with options or in options.expand. An empty object for caching configuration or caching = false is the same thing as timeout = 0
265which always goes to the api and the response is not stored in the cache.
266When timeout is greater than 0 the cache will be checked. There will be a miss when the item is not there or age is larger than timeout in seconds, It will be retrieved from the API and the promise will be added/replaced in the cache.
267So if two resources ask the same href close to each other the call will only be done once.
268When a list resource is asked, all the individual resources will be added in the cache as well on the condition that no server side expansion is added (or expand=summary).
269
270A PUT or DELETE operation might alter the information in the cache therefore the cache distinguishes 3 kinds of hrefs:
271* single resources: they will be only removed on a PUT or DELETE on the resource itself
272* basic lists: this are lists which only have basic parameters limit, offset, keyOffset, hrefs or expand=full, summary or none. They will be removed on a PUT or DELETE of a resource with the same resource path.
273* complex hrefs: All lists with other parameters or server side expanded single resources. They will be deleted on any PUT or DELETE because they can even be invalid because of the changing of other resources.
274
275Be carefull with server side expansion because they are not cached very well.
276
277### batch ###
278
279To write more compacter code there is a Batch class which helps you to add things in batch just in one line.
280On a Batch class you can do the following methods:
281* get(href): adds an object to the batch with GET as verb and href as href.
282* put(href, payload): adds an object to the batch with PUT as verb, href as href, and resource as body.
283* put(resource): adds an object to the batch with PUT as verb, resource.$$meta.permalink as href, and resource as body.
284* post(href, payload): adds an object to the batch with POST as verb, href as href, and resource as body.
285* delete(href): adds an object to the batch with DELETE as verb and href as href.
286* getPayload(): returns the array of the batch. (you can also do batch.array for the same result)
287* send(href, sriClient): does a PUT to href with the build up batch array as payload using sriClient. If you have initialised the batch with a client or got the batch from the client [sriClient.createBatch()] you don't have to add the sriClient here.
288```javascript
289const api = require('@kathondvla/sri-client/node-sri-client')(configuration);
290const Batch = require('@kathondvla/sri-client/batch');
291
292try {
293 const batch = new Batch(api); // OR api.createBatch();
294 batch.put(person.$$meta.permalink, person);
295 batch.delete(person.$$emails.primary.href);
296 batch.post('/persons/changepassword', passwordPayload);
297 await batch.send('/persons/batch'); // OR await api.put('/persons/batch', batch.array)
298} catch (error) {
299 if(error instanceof SriClientError) {
300 console.error(util.inspect(error.body, {depth:7}));
301 console.error(error.stack);
302 } else {
303 console.error(error);
304 }
305}
306```
307
308### error handling ###
309
310If the response is different from status code 200 or 201 or there is no response the response is rejected and an error object is returned of type SriClientError.
311So you can catch errors coming from the sri client and catch http error by filtering on this error, for example:
312
313```javascript
314const SriClientError = require('@kathondvla/sri-client/sri-client-error');
315// create a batch array
316try {
317 await api.put('/batch', batch);
318} catch (error) {
319 if(error instanceof SriClientError) {
320 console.error(util.inspect(error.body, {depth:7}));
321 console.error(error.stack);
322 } else {
323 console.error(error);
324 }
325}
326```
327
328An SriClientError has the following properties:
329
330* status: the status code of the response (null if there was no response)
331* body: payload of the response.
332* getResponseHeader(): function that returns the whole responseHeader [is not working yet]
333* stack: stack trace that leads back to where the api was called from in the code
334
335## common-utils ##
336
337This is a library with common utility functions
338
339#### usage ####
340```javascript
341const commonUtils = require('@kathondvla/sri-client/common-utils');
342```
343
344#### interface ####
345
346* **generateUUID():** returns a generated uuid of version 4.
347* **splitPermalink(permalink):** returns an object with properties key (the key of the permalink) and path (the path of the permalink without the key)
348* **getKeyFromPermalink(permalink):** returns the key within the permalink
349* **getPathFromPermalink(permalink):** returns the pathe of the permalink without the key,
350* **parametersToString(href, parameters):** returns the full path for the combination of the base href and the object of parameters. The parameter names and values are URL encoded.
351* **strip$$Properties(object):** returns a copy of the object with all the properties that start with '$$' removed
352* **strip$$PropertiesFromBatch(batchArray):** returns a copy of the batchArray with all the properties of the body in the batch objects that start with '$$' removed
353
354## date-utils ##
355
356This is a library with utility functions for string dates as specified in the sri api in the format yyyy-MM-dd.
357So if we talk about a date as a string it is in that format.
358If a date as a string is null or undefined it is interpreted as infinitely in the future.
359
360#### usage ####
361```javascript
362const dateUtils = require('@kathondvla/sri-client/date-utils');
363```
364
365#### interface ####
366
367* **getNow():** returns the current date as a string
368* **setNow(dateString):** sets now to another date for the whole library. From now on getNow() will return this date.
369* **toString(date):** return the javascript date as a string
370* **parse(dateString):** returns the dateString as a javascript date
371* **stripTime(isoDateString):** returns the received isoDateString without the time section. YYYY-MM-DDTHH:mm:ss.sssZ -> YYYY-MM-DD
372* **isBeforeOrEqual(a,b):** returns true if a is before or on the same day as b, where a and b are dates as strings
373* **isAfterOrEqual(a,b):** returns true if a is after or on the same day as b, where a and b are dates as strings
374* **isBefore(a,b):** returns true if a is strictly before b, where a and b are dates as strings
375* **isAfter(a,b):** returns true if a is strictly after b, where a and b are dates as strings
376* **getFirst(arrayOfDateStrings):** returns the date that is first in time from arrayOfDateStrings
377* **getLast(arrayOfDateStrings):** returns the date that is last in time from arrayOfDateStrings
378* **isOverlapping(a, b):** returns true if there is an overlapping period between a en b where a and b are objects with a property startDate and endDate (which can be null/undefined)
379* **isCovering(a, b):** returns true if the period of b is completely within the period of a.
380* **isConsecutive(a, b):**: returns true if the periods of a and b are strictly following each other in any order. So b starts on the same date as a ends or a starts on the same date as b ends.
381* **isConsecutiveWithOneDayInBetween(a, b):**: returns true if the periods of a and b are strictly following each other in any order with one day in between. So b starts the day after a ends or a starts the day after b ends.
382* **getStartOfSchoolYear(dateString):** returns the first of september before datestring (the first of september before getNow() if dateString is null),
383* **getEndOfSchoolYear(dateString):** returns the first of september after dateString (the first of september after getNow() if dateString is null),
384* **getClosestSchoolYearSwitch(dateString):** returns the first of september which is the closest to the dateString (the first of september after getNow() if dateString is null) [for all dates in march untill august it returns getEndOfSchoolYear(), for all dates in setember untill februari it returns getStartOfSchoolYear()],
385* **getPreviousDay(dateString, nbOfDays):** returns the date which is the given number of days before dateString, as a string. nbOfDays is optional, the default is 1.
386* **getNextDay(dateString, nbOfDays):** returns the date which is the given number of days after dateString, as a string. nbOfDays is optional, the default is 1.
387* **getPreviousMonth(dateString, nbOfMonths):** returns the date which is the given number of months before dateString, as a string. nbOfMonths is optional, the default is 1.
388* **getNexMonth(dateString, nbOfMonths):** returns the date which is the given number of months after dateString, as a string. nbOfMonths is optional, the default is 1.
389* **getPreviousYear(dateString, nbOfYears):** returns the date which is a given number of years before dateString, as a string. nbOfYears is optional, the default is 1.
390* **getNextYear(dateString, nbOfYears):** returns the date which is the given number of years after dateString, as a string. nbOfYears is optional, the default is 1.
391* **getActiveResources(arrayOfResources, referenceDateString):** returns a new array with only the resources that are active on the referenceDateString (getNow() if dateString is null) from array,
392which is an array of resources with a period. array can also be an array of hrefs that is expanded.
393* **getNonAbolishedResources(arrayOfResources, referenceDateString):** returns a new array with only the resources that are not abolished on the referenceDateString (getNow() if dateString is null) from array,
394which is an array of resources with a period. array can also be an array of hrefs that is expanded.
395* **manageDeletes(resource, options, sriClient):** manages the propagation of deletes for the given resource to it's dependencies. It needs sriClient to query these dependenies. The options are:
396 * batch: a batch array. All references to this resource that should be deleted as well will be added to this batch array. If a depending resource is already present in the batch, it will be removed from the batch since this no longer seems necessary.
397 * references: an array of objects (or one object) with configuration to find the other resources referencing this resource and by consequence should be deleted as well. The configuration has the following properties [we explain this by the example where we delete a basket containing apples and oranges. If we delete the basket, the cookies and the oranges should be deleted as well]:
398 * alias: not required but if you add an alias, the function will return an object with the given alias as a property which contains the referencing resources that should be deleted as well. [For example 'apples', the returnin object will have a property 'apples' which is an array of the apples that were in the basket, which will be the given resource]
399 * href: the path on which the referencing resources can be found. [for example /fruits/apples, we want to delete all apples that reference the given basket]
400 * property: the property name/parameter name of the referencing resource pointing to the given resource. [for example 'basket', the property name within /fruits/apples that is a reference to the baket]
401 * commonReference: If a referencing resource is not referencing directly to the given resource but they are related to each other because they are referencing to the same resource. [For example you are not deleting the basket. But the apples and oranges both refer to a promotion which gave two free apples when buying an orange, upon deleting the orange you want to delete all apples that reference the same 'promotion', it is required that apples an oranges both have a property that have the same property name 'promotion']
402 * subResources: array with property paths to subResources of the reference which also need to be deleted.
403 * parameters: optional parameters to filter on the references. [For example only delete the green apples upon deleting the basket]
404 * filter: function that filters out certain resources in memory
405 * options: an options object that will be passed on as a parameter to the sriClient.getAll function.
406* **manageDateChanges(resource, options, sriClient):** manages the propagation of date changes for the given resource to it's dependencies. It needs an sriClient to query for this dependencies [This works in the same way as deletes but with updates on the period instead of deletes]. The options are:
407 * oldStartDate: the old startDate of the resource before it was updated.
408 * oldEndDate: the old endDate of the resource before it was updated.
409 * batch: a batch array. All references to this resource that should be updated as well will be added to this batch array. If a depending resource is already present in the batch, it will update the body of that batch element.
410 * properties: an array of strings containing the property names of the resource that have a period which should be updated together with the main period of the resource.
411 * intermediateStrategy: strategy to handle resources which start in between the new and the old startDate (or in between the new and the old endDate). Possible values are: 'NONE' (nothing is done with intermediate resources, validation errors will stop the period change from happening), 'ERROR' (this is the default, if there are intermediate resources an error is thrown of type DateError), 'FORCE' (intermediate resources are forced to adapt their period so there are no conflicts)
412 * references: an array of objects (or one object) with configuration to find the other resources referencing this resource and by consequence should have their period updated as well. The configuration has the following properties:
413 * alias: not required but if you add an alias, the function will return an object with the given alias as a property which contains the referencing resources that should be updated as well. If there was no period change the returned object is null.
414 * href: the path on which the referencing resources can be found.
415 * property: the property name/parameter name of the referencing resource pointing to the given resource.
416 * intermediateStrategy: overwrite the general intermediateStrategy for this reference.
417 * commonReference: If a referencing resource is not referencing directly to the given resource but they are related to each other because they are referencing to the same resource.
418 * subResources: array with property paths to subResources of the reference which also need to be updated.
419 * onlyEnlargePeriod: boolean (default is false). If true the period of the referencing is enlarged if the period of the given resource is enlarged, the period will never be shortened.
420 * onlyShortenPeriod: boolean (default is false). If true the period of the referencing is shortened if the period of the given resource is shortened, the period will never be enlarged.
421 * parameters: optional parameters to filter on the references.
422 * filter: function that filters out certain resources in memory
423 * options: an options object that will be passed on as a parameter to the sriClient.getAll function.
424If an error occurs when hanling a periodic reference to the given resource, a DateError is thrown with two properties, a message and the periodic.
425
426## address-utils ##
427
428This is a library with utility functions for address objects as specified in the sri api.
429
430#### usage ####
431```javascript
432const addressUtils = require('@kathondvla/sri-client/address-utils');
433```
434
435#### interface ####
436
437* **printAddress(address):** returns the address as a string in the format {street} {houseNumber} {mailboxNumber}, {zipCode} {subCity}
438* **isSameHouseNumberAndMailbox(a, b):** returns true if sri address a and sri address b have the same mailboxNumber and houseNumber. The match is case insensitive and ingores white spaces and underscores.
439* **isSameStreet(a, b):** returns true if sri address a and sri address b are the same streets. This means a match on the street name in the same city. If both addresses have a streetHref a match is done based on this reference because it is a reference to the same street, independent of how it is spelled. Otherwise A match on street name is case insensitive and takes into account that parts of the name are abbreviated with a dot. For example 'F. Lintsstraat' matches with 'Frederik lintsstraat'.
440* **addSubCityHref(sriAddress, api) [async]:** adds a subCityHref reference to the sriAddress. api is an instance of an sri-client library (can be both the ng-sri-client or the node-sri-client)
441* **addStreetHref(sriAddress, api) [async]:** adds a streetHref reference to the sriAddress. api is an instance of an sri-client library (can be both the ng-sri-client or the node-sri-client)
442
443### Questions ###
444
445Mail to matthias.snellings@katholiekonderwijs.vlaanderen, gunther.claes@katholiekonderwijs.vlaanderen.
446
447[sri-documentation]: https://github.com/dimitrydhondt/sri
448[sri4node-project]: https://github.com/katholiek-onderwijs-vlaanderen/sri4node
449[npm-requestretry]: https://www.npmjs.com/package/requestretry
450[npm-requestretry-strategy]: https://www.npmjs.com/package/requestretry#how-to-define-your-own-retry-strategy
451[npm-requestretry-delaystrategey]: https://www.npmjs.com/package/requestretry#how-to-define-your-own-delay-strategy
452[npm-request]: https://www.npmjs.com/package/request
453[fetch-cache-options]: https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
\No newline at end of file