Skip to content

Commit f4aa1ab

Browse files
committed
handle singleCollaborator field type
1 parent aba3eb5 commit f4aa1ab

File tree

9 files changed

+44
-13
lines changed

9 files changed

+44
-13
lines changed

components/airtable_oauth/actions/create-or-update-record/create-or-update-record.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "airtable_oauth-create-or-update-record",
77
name: "Create or Update Record",
88
description: "Create a new record or update an existing one. [See the documentation](https://airtable.com/developers/web/api/create-records)",
9-
version: "0.1.1",
9+
version: "0.1.2",
1010
type: "action",
1111
props: {
1212
...common.props,

components/airtable_oauth/actions/create-single-record/create-single-record.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "airtable_oauth-create-single-record",
77
name: "Create Single Record",
88
description: "Adds a record to a table.",
9-
version: "0.0.10",
9+
version: "0.0.11",
1010
type: "action",
1111
props: {
1212
...common.props,

components/airtable_oauth/actions/get-record-or-create/get-record-or-create.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "airtable_oauth-get-record-or-create",
77
name: "Get Record Or Create",
88
description: "Get a specific record, or create one if it doesn't exist. [See the documentation](https://airtable.com/developers/web/api/create-records)",
9-
version: "0.0.10",
9+
version: "0.0.12",
1010
type: "action",
1111
props: {
1212
...common.props,

components/airtable_oauth/actions/get-record/get-record.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "airtable_oauth-get-record",
77
name: "Get Record",
88
description: "Get data of a selected record from a table. [See the documentation](https://airtable.com/developers/web/api/get-record)",
9-
version: "0.0.10",
9+
version: "0.0.11",
1010
type: "action",
1111
props: {
1212
...common.props,

components/airtable_oauth/actions/search-records/search-records.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "airtable_oauth-search-records",
66
name: "Search Records",
77
description: "Search for a record by formula or by field value. [See the documentation](https://airtable.com/developers/web/api/list-records)",
8-
version: "0.0.11",
8+
version: "0.0.12",
99
type: "action",
1010
props: {
1111
...common.props,

components/airtable_oauth/actions/update-record/update-record.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "airtable_oauth-update-record",
77
name: "Update Record",
88
description: "Update a single record in a table by Record ID. [See the documentation](https://airtable.com/developers/web/api/update-record)",
9-
version: "0.0.10",
9+
version: "0.0.11",
1010
type: "action",
1111
props: {
1212
...common.props,

components/airtable_oauth/common/actions.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default {
3333
const baseId = ctx.baseId?.value ?? ctx.baseId;
3434
const tableId = ctx.tableId?.value ?? ctx.tableId;
3535

36-
const record = ctx.record ?? makeRecord(ctx);
36+
const record = ctx.record ?? await makeRecord(ctx);
3737

3838
ctx.airtable.validateRecord(record);
3939

@@ -61,7 +61,7 @@ export default {
6161
const recordId = ctx.recordId;
6262

6363
ctx.airtable.validateRecordID(recordId);
64-
const record = ctx.record ?? makeRecord(ctx);
64+
const record = ctx.record ?? await makeRecord(ctx);
6565

6666
let response;
6767
try {

components/airtable_oauth/common/utils.mjs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,48 @@ function makeFieldProps(tableSchema) {
121121
* @param {object} props - A component's props
122122
* @returns {object} a record
123123
*/
124-
function makeRecord(props) {
124+
async function makeRecord(ctx) {
125125
let record = {};
126-
for (const key of Object.keys(props)) {
126+
const fieldTypes = await mapFieldTypes(ctx);
127+
for (const key of Object.keys(ctx)) {
127128
if (key.startsWith(FIELD_PREFIX)) {
128129
const fieldName = key.slice(FIELD_PREFIX.length);
129-
record[fieldName] = props[key];
130+
if (fieldTypes[fieldName] === FieldType.SINGLE_COLLABORATOR) {
131+
record[fieldName] = buildSingleCollaboratorField(ctx[key]);
132+
continue;
133+
}
134+
record[fieldName] = ctx[key];
130135
}
131136
}
132137
return record;
133138
}
134139

140+
async function mapFieldTypes(ctx) {
141+
const baseId = ctx.baseId?.value ?? ctx.baseId;
142+
const tableId = ctx.tableId?.value ?? ctx.tableId;
143+
const { tables } = await ctx.airtable.listTables({
144+
baseId,
145+
});
146+
const tableSchema = tables.find(({ id }) => id === tableId);
147+
const fieldTypes = {};
148+
for (const field of tableSchema?.fields ?? []) {
149+
fieldTypes[field.name] = field.type;
150+
}
151+
return fieldTypes;
152+
}
153+
154+
const isEmail = (str) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(str);
155+
156+
function buildSingleCollaboratorField(value) {
157+
return isEmail(value)
158+
? {
159+
email: value,
160+
}
161+
: {
162+
id: value,
163+
};
164+
}
165+
135166
export {
136167
fieldTypeToPropType,
137168
fieldToProp,

components/airtable_oauth/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/airtable_oauth",
3-
"version": "0.4.3",
3+
"version": "0.4.4",
44
"description": "Pipedream Airtable (OAuth) Components",
55
"main": "airtable_oauth.app.mjs",
66
"keywords": [
@@ -13,7 +13,7 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^1.6.0",
16+
"@pipedream/platform": "^3.0.3",
1717
"airtable": "^0.11.1",
1818
"bottleneck": "^2.19.5",
1919
"lodash.chunk": "^4.2.0",

0 commit comments

Comments
 (0)