easy-airtable-api 0.0.5 → 0.0.6

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/README.md CHANGED
@@ -16,6 +16,11 @@ npm install easy-airtable-api
16
16
 
17
17
  ## Changelog
18
18
 
19
+ ### 0.0.6
20
+
21
+ - Add all available updateRecord options.
22
+ - Fix path to index.d.ts.
23
+
19
24
  ### 0.0.5
20
25
 
21
26
  - Drop CJS build and only support ESM for now.
package/lib/requests.d.ts CHANGED
@@ -11,12 +11,17 @@ export declare function getRecords<Fields>({ apiKey, baseId, tableId, options, }
11
11
  tableId: string;
12
12
  options?: GetRecordsQueryParameters;
13
13
  }): Promise<AirtableRecord<Fields>[]>;
14
- export declare function updateRecord<Fields>({ apiKey, baseId, tableId, recordId, fields, }: {
14
+ export declare function updateRecord<Fields>({ apiKey, baseId, tableId, recordId, fields, options, }: {
15
15
  apiKey: string;
16
16
  baseId: string;
17
17
  tableId: string;
18
18
  recordId: string;
19
19
  fields: object;
20
+ options?: {
21
+ typecast?: boolean;
22
+ returnFieldsByFieldId?: boolean;
23
+ overwriteFieldsNotSpecified?: boolean;
24
+ };
20
25
  }): Promise<AirtableRecord<Fields>>;
21
26
  export declare function updateRecords<Fields>({ apiKey, baseId, tableId, records, options, }: {
22
27
  apiKey: string;
package/lib/requests.js CHANGED
@@ -20,14 +20,18 @@ export async function getRecords({ apiKey, baseId, tableId, options, }) {
20
20
  });
21
21
  return response.records;
22
22
  }
23
- export async function updateRecord({ apiKey, baseId, tableId, recordId, fields, }) {
23
+ export async function updateRecord({ apiKey, baseId, tableId, recordId, fields, options, }) {
24
24
  return await airtableRequest({
25
25
  apiKey,
26
26
  baseId,
27
27
  tableId,
28
28
  endpoint: `/${recordId}`,
29
- method: 'PATCH',
30
- body: { fields },
29
+ method: options?.overwriteFieldsNotSpecified === true ? 'PUT' : 'PATCH',
30
+ body: {
31
+ fields,
32
+ typecast: options?.typecast === true ? true : false,
33
+ returnFieldsByFieldId: options?.returnFieldsByFieldId === true ? true : false,
34
+ },
31
35
  });
32
36
  }
33
37
  export async function updateRecords({ apiKey, baseId, tableId, records, options, }) {
@@ -99,10 +103,12 @@ function validateResponse(response) {
99
103
  throw new Error('Table or Record not found.');
100
104
  else if (statusCode === 413)
101
105
  throw new Error('Request body is too large');
102
- else if (statusCode === 422)
103
- throw new Error('Operation cannot be processed');
104
- else if (statusCode === 429)
106
+ else if (statusCode === 422) {
107
+ throw new Error('Operation cannot be processed. Do the field names match?');
108
+ }
109
+ else if (statusCode === 429) {
105
110
  throw new Error('Too many request to Airtable server.');
111
+ }
106
112
  else if (statusCode === 500)
107
113
  throw new Error('Airtable Server Error');
108
114
  else if (statusCode === 503)
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "easy-airtable-api",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "description": "An easy way to connect to Airtable via their API.",
6
6
  "main": "lib/index.js",
7
- "types": "lib/types/index.d.ts",
7
+ "types": "lib/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
10
  "import": "./lib/index.js"