@zapier/zapier-sdk 0.34.0 → 0.35.0
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/CHANGELOG.md +12 -0
- package/README.md +341 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +10 -2
- package/dist/api/types.d.ts +2 -1
- package/dist/api/types.d.ts.map +1 -1
- package/dist/formatters/index.d.ts +2 -0
- package/dist/formatters/index.d.ts.map +1 -0
- package/dist/formatters/index.js +1 -0
- package/dist/formatters/tableRecord.d.ts +6 -0
- package/dist/formatters/tableRecord.d.ts.map +1 -0
- package/dist/formatters/tableRecord.js +23 -0
- package/dist/index.cjs +1828 -35
- package/dist/index.d.mts +644 -70
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.mjs +1807 -36
- package/dist/plugins/apps/schemas.d.ts +11 -11
- package/dist/plugins/apps/schemas.d.ts.map +1 -1
- package/dist/plugins/deleteClientCredentials/index.d.ts.map +1 -1
- package/dist/plugins/deleteClientCredentials/index.js +1 -1
- package/dist/plugins/registry/index.d.ts.map +1 -1
- package/dist/plugins/registry/index.js +4 -0
- package/dist/plugins/tables/createTable/index.d.ts +18 -0
- package/dist/plugins/tables/createTable/index.d.ts.map +1 -0
- package/dist/plugins/tables/createTable/index.js +48 -0
- package/dist/plugins/tables/createTable/schemas.d.ts +37 -0
- package/dist/plugins/tables/createTable/schemas.d.ts.map +1 -0
- package/dist/plugins/tables/createTable/schemas.js +16 -0
- package/dist/plugins/tables/createTableFields/index.d.ts +18 -0
- package/dist/plugins/tables/createTableFields/index.d.ts.map +1 -0
- package/dist/plugins/tables/createTableFields/index.js +49 -0
- package/dist/plugins/tables/createTableFields/schemas.d.ts +192 -0
- package/dist/plugins/tables/createTableFields/schemas.d.ts.map +1 -0
- package/dist/plugins/tables/createTableFields/schemas.js +42 -0
- package/dist/plugins/tables/createTableRecords/index.d.ts +18 -0
- package/dist/plugins/tables/createTableRecords/index.d.ts.map +1 -0
- package/dist/plugins/tables/createTableRecords/index.js +67 -0
- package/dist/plugins/tables/createTableRecords/schemas.d.ts +57 -0
- package/dist/plugins/tables/createTableRecords/schemas.d.ts.map +1 -0
- package/dist/plugins/tables/createTableRecords/schemas.js +35 -0
- package/dist/plugins/tables/deleteTable/index.d.ts +18 -0
- package/dist/plugins/tables/deleteTable/index.d.ts.map +1 -0
- package/dist/plugins/tables/deleteTable/index.js +43 -0
- package/dist/plugins/tables/deleteTable/schemas.d.ts +15 -0
- package/dist/plugins/tables/deleteTable/schemas.d.ts.map +1 -0
- package/dist/plugins/tables/deleteTable/schemas.js +9 -0
- package/dist/plugins/tables/deleteTableFields/index.d.ts +18 -0
- package/dist/plugins/tables/deleteTableFields/index.d.ts.map +1 -0
- package/dist/plugins/tables/deleteTableFields/index.js +50 -0
- package/dist/plugins/tables/deleteTableFields/schemas.d.ts +16 -0
- package/dist/plugins/tables/deleteTableFields/schemas.d.ts.map +1 -0
- package/dist/plugins/tables/deleteTableFields/schemas.js +13 -0
- package/dist/plugins/tables/deleteTableRecords/index.d.ts +18 -0
- package/dist/plugins/tables/deleteTableRecords/index.d.ts.map +1 -0
- package/dist/plugins/tables/deleteTableRecords/index.js +44 -0
- package/dist/plugins/tables/deleteTableRecords/schemas.d.ts +16 -0
- package/dist/plugins/tables/deleteTableRecords/schemas.d.ts.map +1 -0
- package/dist/plugins/tables/deleteTableRecords/schemas.js +14 -0
- package/dist/plugins/tables/getTable/index.d.ts +20 -0
- package/dist/plugins/tables/getTable/index.d.ts.map +1 -0
- package/dist/plugins/tables/getTable/index.js +48 -0
- package/dist/plugins/tables/getTable/schemas.d.ts +34 -0
- package/dist/plugins/tables/getTable/schemas.d.ts.map +1 -0
- package/dist/plugins/tables/getTable/schemas.js +15 -0
- package/dist/plugins/tables/getTableRecord/index.d.ts +18 -0
- package/dist/plugins/tables/getTableRecord/index.d.ts.map +1 -0
- package/dist/plugins/tables/getTableRecord/index.js +60 -0
- package/dist/plugins/tables/getTableRecord/schemas.d.ts +51 -0
- package/dist/plugins/tables/getTableRecord/schemas.d.ts.map +1 -0
- package/dist/plugins/tables/getTableRecord/schemas.js +44 -0
- package/dist/plugins/tables/listTableFields/index.d.ts +18 -0
- package/dist/plugins/tables/listTableFields/index.d.ts.map +1 -0
- package/dist/plugins/tables/listTableFields/index.js +58 -0
- package/dist/plugins/tables/listTableFields/schemas.d.ts +180 -0
- package/dist/plugins/tables/listTableFields/schemas.d.ts.map +1 -0
- package/dist/plugins/tables/listTableFields/schemas.js +77 -0
- package/dist/plugins/tables/listTableRecords/index.d.ts +24 -0
- package/dist/plugins/tables/listTableRecords/index.d.ts.map +1 -0
- package/dist/plugins/tables/listTableRecords/index.js +95 -0
- package/dist/plugins/tables/listTableRecords/schemas.d.ts +120 -0
- package/dist/plugins/tables/listTableRecords/schemas.d.ts.map +1 -0
- package/dist/plugins/tables/listTableRecords/schemas.js +74 -0
- package/dist/plugins/tables/listTables/index.d.ts +24 -0
- package/dist/plugins/tables/listTables/index.d.ts.map +1 -0
- package/dist/plugins/tables/listTables/index.js +83 -0
- package/dist/plugins/tables/listTables/schemas.d.ts +78 -0
- package/dist/plugins/tables/listTables/schemas.d.ts.map +1 -0
- package/dist/plugins/tables/listTables/schemas.js +63 -0
- package/dist/plugins/tables/updateTableRecords/index.d.ts +18 -0
- package/dist/plugins/tables/updateTableRecords/index.d.ts.map +1 -0
- package/dist/plugins/tables/updateTableRecords/index.js +68 -0
- package/dist/plugins/tables/updateTableRecords/schemas.d.ts +59 -0
- package/dist/plugins/tables/updateTableRecords/schemas.d.ts.map +1 -0
- package/dist/plugins/tables/updateTableRecords/schemas.js +35 -0
- package/dist/plugins/tables/utils.d.ts +63 -0
- package/dist/plugins/tables/utils.d.ts.map +1 -0
- package/dist/plugins/tables/utils.js +262 -0
- package/dist/resolvers/index.d.ts +8 -0
- package/dist/resolvers/index.d.ts.map +1 -1
- package/dist/resolvers/index.js +8 -0
- package/dist/resolvers/tableFieldIds.d.ts +6 -0
- package/dist/resolvers/tableFieldIds.d.ts.map +1 -0
- package/dist/resolvers/tableFieldIds.js +19 -0
- package/dist/resolvers/tableFields.d.ts +3 -0
- package/dist/resolvers/tableFields.d.ts.map +1 -0
- package/dist/resolvers/tableFields.js +31 -0
- package/dist/resolvers/tableFilters.d.ts +5 -0
- package/dist/resolvers/tableFilters.d.ts.map +1 -0
- package/dist/resolvers/tableFilters.js +74 -0
- package/dist/resolvers/tableId.d.ts +4 -0
- package/dist/resolvers/tableId.d.ts.map +1 -0
- package/dist/resolvers/tableId.js +19 -0
- package/dist/resolvers/tableName.d.ts +3 -0
- package/dist/resolvers/tableName.d.ts.map +1 -0
- package/dist/resolvers/tableName.js +5 -0
- package/dist/resolvers/tableRecordId.d.ts +9 -0
- package/dist/resolvers/tableRecordId.d.ts.map +1 -0
- package/dist/resolvers/tableRecordId.js +48 -0
- package/dist/resolvers/tableRecords.d.ts +8 -0
- package/dist/resolvers/tableRecords.d.ts.map +1 -0
- package/dist/resolvers/tableRecords.js +77 -0
- package/dist/resolvers/tableSort.d.ts +5 -0
- package/dist/resolvers/tableSort.d.ts.map +1 -0
- package/dist/resolvers/tableSort.js +43 -0
- package/dist/sdk.d.ts +73 -1
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +25 -0
- package/dist/types/sdk.d.ts +16 -1
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/utils/pagination-utils.d.ts +24 -0
- package/dist/utils/pagination-utils.d.ts.map +1 -1
- package/dist/utils/pagination-utils.js +78 -0
- package/dist/utils/schema-utils.d.ts +33 -5
- package/dist/utils/schema-utils.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ApiClient } from "../../api";
|
|
3
|
+
import type { TableApiItem, TableItem } from "./listTables/schemas";
|
|
4
|
+
import type { RecordApiItem, RecordItem } from "./getTableRecord/schemas";
|
|
5
|
+
import type { FieldApiItem, FieldItem } from "./listTableFields/schemas";
|
|
6
|
+
export declare function formatFieldValue(v: unknown): string;
|
|
7
|
+
/**
|
|
8
|
+
* Convert a field ID to its numeric form for the Tables API.
|
|
9
|
+
* Accepts "f6", "6", or 6 and returns 6.
|
|
10
|
+
*/
|
|
11
|
+
export declare function toNumericFieldId(id: string | number): number;
|
|
12
|
+
export declare function transformTableItem(apiItem: TableApiItem): TableItem;
|
|
13
|
+
export declare function transformFieldItem(apiItem: FieldApiItem): FieldItem;
|
|
14
|
+
export declare function transformRecordItem(apiItem: RecordApiItem): RecordItem;
|
|
15
|
+
/**
|
|
16
|
+
* Check a record API item for field-level validation errors and throw if any
|
|
17
|
+
* are present. The errors dict is keyed by field ID, and each value has
|
|
18
|
+
* `{s, v, e, h}` where `h` is the human-friendly message and `e` is the
|
|
19
|
+
* technical one.
|
|
20
|
+
*/
|
|
21
|
+
export declare function throwOnRecordErrors(record: RecordApiItem): void;
|
|
22
|
+
/**
|
|
23
|
+
* Check an API response for top-level validation errors (in `meta.errors`)
|
|
24
|
+
* and throw if any are present.
|
|
25
|
+
*/
|
|
26
|
+
export declare function throwOnResponseErrors(response: {
|
|
27
|
+
meta?: {
|
|
28
|
+
errors?: unknown[];
|
|
29
|
+
} | null;
|
|
30
|
+
}): void;
|
|
31
|
+
export declare const KeyModeSchema: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
32
|
+
names: "names";
|
|
33
|
+
ids: "ids";
|
|
34
|
+
}>>>;
|
|
35
|
+
export type KeyMode = z.infer<typeof KeyModeSchema>;
|
|
36
|
+
export declare function isFieldId(key: string): boolean;
|
|
37
|
+
export declare const NESTED_COMPONENTS: Record<string, Set<string>>;
|
|
38
|
+
/**
|
|
39
|
+
* Resolve an array of field keys (names like "Email" or IDs like "f6", "6", 6)
|
|
40
|
+
* to numeric field IDs for the API. Only fetches field metadata if any
|
|
41
|
+
* non-ID keys are present.
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveFieldKeys({ api, tableId, fieldKeys, }: {
|
|
44
|
+
api: ApiClient;
|
|
45
|
+
tableId: string;
|
|
46
|
+
fieldKeys: Array<string | number>;
|
|
47
|
+
}): Promise<number[]>;
|
|
48
|
+
export interface FieldKeyTranslator {
|
|
49
|
+
translateInput(data: Record<string, unknown>): Record<string, unknown>;
|
|
50
|
+
translateOutput(data: Record<string, unknown>): Record<string, unknown>;
|
|
51
|
+
translateFieldKey(key: string): string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolve the field mapping for a table and return a translator.
|
|
55
|
+
* Fetches field metadata from the API once (when keyMode is "names"),
|
|
56
|
+
* then all translate methods are synchronous.
|
|
57
|
+
*/
|
|
58
|
+
export declare function createFieldKeyTranslator({ api, tableId, keyMode, }: {
|
|
59
|
+
api: ApiClient;
|
|
60
|
+
tableId: string;
|
|
61
|
+
keyMode: KeyMode;
|
|
62
|
+
}): Promise<FieldKeyTranslator>;
|
|
63
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugins/tables/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEzE,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAUnD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAS5D;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,CAYnE;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,CAUnE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,UAAU,CAOtE;AAkCD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAgB/D;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE;IAC9C,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,EAAE,CAAA;KAAE,GAAG,IAAI,CAAC;CACtC,GAAG,IAAI,CASP;AAED,eAAO,MAAM,aAAa;;;IAMvB,CAAC;AAEJ,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAIpD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE9C;AAED,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAKzD,CAAC;AA6CF;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,GAAG,EACH,OAAO,EACP,SAAS,GACV,EAAE;IACD,GAAG,EAAE,SAAS,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;CACnC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAyBpB;AAED,MAAM,WAAW,kBAAkB;IACjC,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvE,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxE,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACxC;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB,CAAC,EAC7C,GAAG,EACH,OAAO,EACP,OAAO,GACR,EAAE;IACD,GAAG,EAAE,SAAS,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAkF9B"}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ZapierValidationError } from "../../types/errors";
|
|
3
|
+
export function formatFieldValue(v) {
|
|
4
|
+
if (v == null)
|
|
5
|
+
return "";
|
|
6
|
+
if (typeof v === "object") {
|
|
7
|
+
try {
|
|
8
|
+
return JSON.stringify(v);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return String(v);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return String(v);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Convert a field ID to its numeric form for the Tables API.
|
|
18
|
+
* Accepts "f6", "6", or 6 and returns 6.
|
|
19
|
+
*/
|
|
20
|
+
export function toNumericFieldId(id) {
|
|
21
|
+
if (typeof id === "number")
|
|
22
|
+
return id;
|
|
23
|
+
const num = parseInt(id.replace(/^f/, ""), 10);
|
|
24
|
+
if (isNaN(num)) {
|
|
25
|
+
throw new ZapierValidationError(`Invalid field ID: "${id}". Expected a numeric ID like "f6", "6", or 6.`);
|
|
26
|
+
}
|
|
27
|
+
return num;
|
|
28
|
+
}
|
|
29
|
+
export function transformTableItem(apiItem) {
|
|
30
|
+
return {
|
|
31
|
+
id: apiItem.id,
|
|
32
|
+
name: apiItem.name,
|
|
33
|
+
description: apiItem.description ?? undefined,
|
|
34
|
+
created_at: apiItem.created_at,
|
|
35
|
+
edited_at: apiItem.edited_at,
|
|
36
|
+
kind: apiItem.kind,
|
|
37
|
+
owner_account_id: String(apiItem.owner_account_id),
|
|
38
|
+
profile_id: String(apiItem.owner_zapier_customuser_id),
|
|
39
|
+
parent_table_id: apiItem.parent_table_id ?? undefined,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function transformFieldItem(apiItem) {
|
|
43
|
+
return {
|
|
44
|
+
id: `f${apiItem.id}`,
|
|
45
|
+
type: apiItem.type,
|
|
46
|
+
name: apiItem.name,
|
|
47
|
+
created_at: apiItem.created_at,
|
|
48
|
+
edited_at: apiItem.edited_at,
|
|
49
|
+
options: apiItem.options,
|
|
50
|
+
config: apiItem.config,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function transformRecordItem(apiItem) {
|
|
54
|
+
return {
|
|
55
|
+
id: apiItem.id,
|
|
56
|
+
data: apiItem.data,
|
|
57
|
+
created_at: apiItem.created_at,
|
|
58
|
+
edited_at: apiItem.edited_at,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function formatRecordError(fieldId, err) {
|
|
62
|
+
const message = err.h || err.e || "validation error";
|
|
63
|
+
if (err.v !== undefined) {
|
|
64
|
+
return `Field ${fieldId}: ${message} (value: ${JSON.stringify(err.v)})`;
|
|
65
|
+
}
|
|
66
|
+
return `Field ${fieldId}: ${message}`;
|
|
67
|
+
}
|
|
68
|
+
function formatResponseError(err) {
|
|
69
|
+
const message = err.human_title || err.title || "Unknown error";
|
|
70
|
+
if (err.meta && Object.keys(err.meta).length > 0) {
|
|
71
|
+
const metaParts = Object.entries(err.meta)
|
|
72
|
+
.map(([key, val]) => `${key}: ${JSON.stringify(val)}`)
|
|
73
|
+
.join(", ");
|
|
74
|
+
return `${message} (${metaParts})`;
|
|
75
|
+
}
|
|
76
|
+
return message;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check a record API item for field-level validation errors and throw if any
|
|
80
|
+
* are present. The errors dict is keyed by field ID, and each value has
|
|
81
|
+
* `{s, v, e, h}` where `h` is the human-friendly message and `e` is the
|
|
82
|
+
* technical one.
|
|
83
|
+
*/
|
|
84
|
+
export function throwOnRecordErrors(record) {
|
|
85
|
+
if (!record.errors)
|
|
86
|
+
return;
|
|
87
|
+
const messages = [];
|
|
88
|
+
for (const [fieldId, error] of Object.entries(record.errors)) {
|
|
89
|
+
const err = error;
|
|
90
|
+
if (err.s === "error") {
|
|
91
|
+
messages.push(formatRecordError(fieldId, err));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (messages.length > 0) {
|
|
95
|
+
throw new ZapierValidationError(`Record ${record.id} has errors: ${messages.join("; ")}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Check an API response for top-level validation errors (in `meta.errors`)
|
|
100
|
+
* and throw if any are present.
|
|
101
|
+
*/
|
|
102
|
+
export function throwOnResponseErrors(response) {
|
|
103
|
+
const errors = response.meta?.errors;
|
|
104
|
+
if (!errors || errors.length === 0)
|
|
105
|
+
return;
|
|
106
|
+
const messages = errors.map((err) => formatResponseError(err));
|
|
107
|
+
throw new ZapierValidationError(messages.join("; "));
|
|
108
|
+
}
|
|
109
|
+
export const KeyModeSchema = z
|
|
110
|
+
.enum(["names", "ids"])
|
|
111
|
+
.optional()
|
|
112
|
+
.default("names")
|
|
113
|
+
.describe('How to interpret field keys in record data. "names" (default) uses human-readable field names, "ids" uses raw field IDs (f1, f2).');
|
|
114
|
+
const FIELD_ID_PATTERN = /^f\d+$/;
|
|
115
|
+
export function isFieldId(key) {
|
|
116
|
+
return FIELD_ID_PATTERN.test(key);
|
|
117
|
+
}
|
|
118
|
+
export const NESTED_COMPONENTS = {
|
|
119
|
+
labeled_string: new Set(["value"]),
|
|
120
|
+
ai_formula: new Set(["value"]),
|
|
121
|
+
link: new Set(["link", "text"]),
|
|
122
|
+
linked_record: new Set(["label", "source"]),
|
|
123
|
+
};
|
|
124
|
+
async function getFieldMapping(api, tableId, keyMode) {
|
|
125
|
+
if (keyMode === "ids") {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
// "names" mode — fetch from API
|
|
129
|
+
const rawResponse = await api.get(`/tables/api/v1/tables/${tableId}/fields`, {
|
|
130
|
+
authRequired: true,
|
|
131
|
+
});
|
|
132
|
+
const data = rawResponse.data;
|
|
133
|
+
// First match wins for duplicate names
|
|
134
|
+
const nameToId = new Map();
|
|
135
|
+
const idToName = new Map();
|
|
136
|
+
const idToType = new Map();
|
|
137
|
+
for (const field of data) {
|
|
138
|
+
const id = `f${field.id}`;
|
|
139
|
+
if (!nameToId.has(field.name)) {
|
|
140
|
+
nameToId.set(field.name, id);
|
|
141
|
+
}
|
|
142
|
+
if (!idToName.has(id)) {
|
|
143
|
+
idToName.set(id, field.name);
|
|
144
|
+
}
|
|
145
|
+
idToType.set(id, field.type);
|
|
146
|
+
}
|
|
147
|
+
return { nameToId, idToName, idToType };
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Resolve an array of field keys (names like "Email" or IDs like "f6", "6", 6)
|
|
151
|
+
* to numeric field IDs for the API. Only fetches field metadata if any
|
|
152
|
+
* non-ID keys are present.
|
|
153
|
+
*/
|
|
154
|
+
export async function resolveFieldKeys({ api, tableId, fieldKeys, }) {
|
|
155
|
+
const allAreIds = fieldKeys.every((key) => typeof key === "number" || /^(f?\d+)$/.test(key));
|
|
156
|
+
if (allAreIds) {
|
|
157
|
+
return fieldKeys.map(toNumericFieldId);
|
|
158
|
+
}
|
|
159
|
+
const mapping = await getFieldMapping(api, tableId, "names");
|
|
160
|
+
if (!mapping) {
|
|
161
|
+
return fieldKeys.map(toNumericFieldId);
|
|
162
|
+
}
|
|
163
|
+
return fieldKeys.map((key) => {
|
|
164
|
+
if (typeof key === "number")
|
|
165
|
+
return key;
|
|
166
|
+
if (FIELD_ID_PATTERN.test(key))
|
|
167
|
+
return toNumericFieldId(key);
|
|
168
|
+
const id = mapping.nameToId.get(key);
|
|
169
|
+
if (!id) {
|
|
170
|
+
throw new ZapierValidationError(`Unknown field name: "${key}". Use a valid field name or ID.`);
|
|
171
|
+
}
|
|
172
|
+
return toNumericFieldId(id);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Resolve the field mapping for a table and return a translator.
|
|
177
|
+
* Fetches field metadata from the API once (when keyMode is "names"),
|
|
178
|
+
* then all translate methods are synchronous.
|
|
179
|
+
*/
|
|
180
|
+
export async function createFieldKeyTranslator({ api, tableId, keyMode, }) {
|
|
181
|
+
const mapping = await getFieldMapping(api, tableId, keyMode);
|
|
182
|
+
return {
|
|
183
|
+
translateInput(data) {
|
|
184
|
+
if (!mapping)
|
|
185
|
+
return data;
|
|
186
|
+
const result = {};
|
|
187
|
+
for (const [key, value] of Object.entries(data)) {
|
|
188
|
+
if (FIELD_ID_PATTERN.test(key) && mapping.idToName.has(key)) {
|
|
189
|
+
result[key] = value;
|
|
190
|
+
}
|
|
191
|
+
else if (mapping.nameToId.has(key)) {
|
|
192
|
+
result[mapping.nameToId.get(key)] = value;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
result[key] = value;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
},
|
|
200
|
+
translateOutput(data) {
|
|
201
|
+
if (!mapping)
|
|
202
|
+
return data;
|
|
203
|
+
const result = {};
|
|
204
|
+
for (const [key, value] of Object.entries(data)) {
|
|
205
|
+
if (mapping.idToName.has(key)) {
|
|
206
|
+
result[mapping.idToName.get(key)] = value;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
result[key] = value;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
},
|
|
214
|
+
translateFieldKey(key) {
|
|
215
|
+
if (!mapping)
|
|
216
|
+
return key;
|
|
217
|
+
if (FIELD_ID_PATTERN.test(key) && mapping.idToName.has(key)) {
|
|
218
|
+
// Auto-append component for single-component types (e.g., f3 → f3__value for labeled_string)
|
|
219
|
+
const fieldType = mapping.idToType.get(key);
|
|
220
|
+
if (fieldType) {
|
|
221
|
+
const components = NESTED_COMPONENTS[fieldType];
|
|
222
|
+
if (components?.size === 1) {
|
|
223
|
+
return `${key}__${[...components][0]}`;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return key;
|
|
227
|
+
}
|
|
228
|
+
if (mapping.nameToId.has(key)) {
|
|
229
|
+
const fieldId = mapping.nameToId.get(key);
|
|
230
|
+
// Auto-append component for single-component types (e.g., Status → f3__value for labeled_string)
|
|
231
|
+
const fieldType = mapping.idToType.get(fieldId);
|
|
232
|
+
if (fieldType) {
|
|
233
|
+
const components = NESTED_COMPONENTS[fieldType];
|
|
234
|
+
if (components?.size === 1) {
|
|
235
|
+
return `${fieldId}__${[...components][0]}`;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return fieldId;
|
|
239
|
+
}
|
|
240
|
+
// Handle nested component syntax (e.g., "Status__value" → "f3__value")
|
|
241
|
+
const sepIndex = key.lastIndexOf("__");
|
|
242
|
+
if (sepIndex > 0) {
|
|
243
|
+
const prefix = key.slice(0, sepIndex);
|
|
244
|
+
const component = key.slice(sepIndex + 2);
|
|
245
|
+
let fieldId;
|
|
246
|
+
if (FIELD_ID_PATTERN.test(prefix) && mapping.idToName.has(prefix)) {
|
|
247
|
+
fieldId = prefix;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
fieldId = mapping.nameToId.get(prefix);
|
|
251
|
+
}
|
|
252
|
+
if (fieldId) {
|
|
253
|
+
const fieldType = mapping.idToType.get(fieldId);
|
|
254
|
+
if (fieldType && NESTED_COMPONENTS[fieldType]?.has(component)) {
|
|
255
|
+
return `${fieldId}__${component}`;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return key;
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
}
|
|
@@ -11,4 +11,12 @@ export { inputFieldKeyResolver } from "./inputFieldKey";
|
|
|
11
11
|
export { inputsAllOptionalResolver } from "./inputs";
|
|
12
12
|
export { clientCredentialsNameResolver } from "./clientCredentialsName";
|
|
13
13
|
export { clientIdResolver } from "./clientId";
|
|
14
|
+
export { tableIdResolver } from "./tableId";
|
|
15
|
+
export { tableRecordIdResolver, tableRecordIdsResolver } from "./tableRecordId";
|
|
16
|
+
export { tableFieldIdsResolver } from "./tableFieldIds";
|
|
17
|
+
export { tableNameResolver } from "./tableName";
|
|
18
|
+
export { tableFieldsResolver } from "./tableFields";
|
|
19
|
+
export { tableRecordsResolver, tableUpdateRecordsResolver, } from "./tableRecords";
|
|
20
|
+
export { tableFiltersResolver } from "./tableFilters";
|
|
21
|
+
export { tableSortResolver } from "./tableSort";
|
|
14
22
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resolvers/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AAGxB,mDAAmD;AACnD,OAAO,EAAE,oBAAoB,IAAI,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAClF,0DAA0D;AAC1D,OAAO,EAAE,2BAA2B,IAAI,+BAA+B,EAAE,MAAM,gBAAgB,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resolvers/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AAGxB,mDAAmD;AACnD,OAAO,EAAE,oBAAoB,IAAI,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAClF,0DAA0D;AAC1D,OAAO,EAAE,2BAA2B,IAAI,+BAA+B,EAAE,MAAM,gBAAgB,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EACL,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/resolvers/index.js
CHANGED
|
@@ -13,3 +13,11 @@ export { inputFieldKeyResolver } from "./inputFieldKey";
|
|
|
13
13
|
export { inputsAllOptionalResolver } from "./inputs";
|
|
14
14
|
export { clientCredentialsNameResolver } from "./clientCredentialsName";
|
|
15
15
|
export { clientIdResolver } from "./clientId";
|
|
16
|
+
export { tableIdResolver } from "./tableId";
|
|
17
|
+
export { tableRecordIdResolver, tableRecordIdsResolver } from "./tableRecordId";
|
|
18
|
+
export { tableFieldIdsResolver } from "./tableFieldIds";
|
|
19
|
+
export { tableNameResolver } from "./tableName";
|
|
20
|
+
export { tableFieldsResolver } from "./tableFields";
|
|
21
|
+
export { tableRecordsResolver, tableUpdateRecordsResolver, } from "./tableRecords";
|
|
22
|
+
export { tableFiltersResolver } from "./tableFilters";
|
|
23
|
+
export { tableSortResolver } from "./tableSort";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DynamicResolver } from "../utils/schema-utils";
|
|
2
|
+
import type { FieldItem } from "../plugins/tables/listTableFields/schemas";
|
|
3
|
+
export declare const tableFieldIdsResolver: DynamicResolver<FieldItem, {
|
|
4
|
+
tableId: string;
|
|
5
|
+
}>;
|
|
6
|
+
//# sourceMappingURL=tableFieldIds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableFieldIds.d.ts","sourceRoot":"","sources":["../../src/resolvers/tableFieldIds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AAE3E,eAAO,MAAM,qBAAqB,EAAE,eAAe,CACjD,SAAS,EACT;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAoBpB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const tableFieldIdsResolver = {
|
|
2
|
+
type: "dynamic",
|
|
3
|
+
depends: ["tableId"],
|
|
4
|
+
fetch: (sdk, params) => {
|
|
5
|
+
return sdk.listTableFields({ tableId: params.tableId });
|
|
6
|
+
},
|
|
7
|
+
prompt: (fields) => ({
|
|
8
|
+
type: "checkbox",
|
|
9
|
+
name: "fieldKeys",
|
|
10
|
+
message: "Select fields:",
|
|
11
|
+
choices: fields.map((field) => ({
|
|
12
|
+
name: `${field.name} (${field.id}, ${field.type})`,
|
|
13
|
+
value: field.id,
|
|
14
|
+
})),
|
|
15
|
+
validate: (value) => Array.isArray(value) && value.length > 0
|
|
16
|
+
? true
|
|
17
|
+
: "Select at least one field",
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableFields.d.ts","sourceRoot":"","sources":["../../src/resolvers/tableFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,uBAAuB,CAAC;AA8B3E,eAAO,MAAM,mBAAmB,EAAE,aAIjC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FieldTypeSchema } from "../plugins/tables/listTableFields/schemas";
|
|
2
|
+
// Get the field type values from the schema
|
|
3
|
+
const fieldTypeChoices = FieldTypeSchema.options.map((type) => ({
|
|
4
|
+
label: type,
|
|
5
|
+
value: type,
|
|
6
|
+
}));
|
|
7
|
+
const singleFieldResolver = {
|
|
8
|
+
type: "fields",
|
|
9
|
+
fetch: async () => {
|
|
10
|
+
return [
|
|
11
|
+
{
|
|
12
|
+
type: "input_field",
|
|
13
|
+
key: "type",
|
|
14
|
+
title: "Field type",
|
|
15
|
+
is_required: true,
|
|
16
|
+
choices: fieldTypeChoices,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
type: "input_field",
|
|
20
|
+
key: "name",
|
|
21
|
+
title: "Field name",
|
|
22
|
+
is_required: true,
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
export const tableFieldsResolver = {
|
|
28
|
+
type: "array",
|
|
29
|
+
fetch: async () => singleFieldResolver,
|
|
30
|
+
minItems: 1,
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableFilters.d.ts","sourceRoot":"","sources":["../../src/resolvers/tableFilters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAGd,MAAM,uBAAuB,CAAC;AA6E/B,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAUnE,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { NESTED_COMPONENTS } from "../plugins/tables/utils";
|
|
2
|
+
const FILTER_OPERATORS = [
|
|
3
|
+
{ label: "equals", value: "exact" },
|
|
4
|
+
{ label: "not equals", value: "different" },
|
|
5
|
+
{ label: "contains", value: "contains" },
|
|
6
|
+
{ label: "contains (case-insensitive)", value: "icontains" },
|
|
7
|
+
{ label: "starts with", value: "startswith" },
|
|
8
|
+
{ label: "search", value: "search" },
|
|
9
|
+
{ label: "greater than", value: "gt" },
|
|
10
|
+
{ label: "greater than or equal", value: "gte" },
|
|
11
|
+
{ label: "less than", value: "lt" },
|
|
12
|
+
{ label: "less than or equal", value: "lte" },
|
|
13
|
+
{ label: "in range", value: "range" },
|
|
14
|
+
{ label: "in list", value: "in" },
|
|
15
|
+
{ label: "is empty", value: "isnull" },
|
|
16
|
+
{ label: "is within (date)", value: "is_within" },
|
|
17
|
+
];
|
|
18
|
+
function createSingleFilterResolver({ sdk, tableId, }) {
|
|
19
|
+
return {
|
|
20
|
+
type: "fields",
|
|
21
|
+
fetch: async () => {
|
|
22
|
+
const { data: fields } = await sdk.listTableFields({ tableId });
|
|
23
|
+
const fieldChoices = fields.flatMap((field) => {
|
|
24
|
+
const components = NESTED_COMPONENTS[field.type];
|
|
25
|
+
if (components && components.size > 1) {
|
|
26
|
+
return [...components].map((component) => ({
|
|
27
|
+
label: `${field.name}__${component} (${field.id}, ${field.type})`,
|
|
28
|
+
value: `${field.name}__${component}`,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
label: `${field.name} (${field.id}${components ? `, ${field.type}` : ""})`,
|
|
33
|
+
value: components
|
|
34
|
+
? `${field.name}__${[...components][0]}`
|
|
35
|
+
: field.name,
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
const fieldItems = [
|
|
39
|
+
{
|
|
40
|
+
type: "input_field",
|
|
41
|
+
key: "fieldKey",
|
|
42
|
+
title: "Field",
|
|
43
|
+
is_required: true,
|
|
44
|
+
choices: fieldChoices,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: "input_field",
|
|
48
|
+
key: "operator",
|
|
49
|
+
title: "Operator",
|
|
50
|
+
is_required: true,
|
|
51
|
+
choices: FILTER_OPERATORS,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: "input_field",
|
|
55
|
+
key: "value",
|
|
56
|
+
title: "Value",
|
|
57
|
+
is_required: false,
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
return fieldItems;
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export const tableFiltersResolver = {
|
|
65
|
+
type: "array",
|
|
66
|
+
depends: ["tableId"],
|
|
67
|
+
fetch: async (sdk, params) => {
|
|
68
|
+
return createSingleFilterResolver({
|
|
69
|
+
sdk,
|
|
70
|
+
tableId: params.tableId,
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
minItems: 0,
|
|
74
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableId.d.ts","sourceRoot":"","sources":["../../src/resolvers/tableId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAGtE,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,SAAS,EAAE,EAAE,CAiB1D,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { concatPaginated } from "../utils/pagination-utils";
|
|
2
|
+
export const tableIdResolver = {
|
|
3
|
+
type: "dynamic",
|
|
4
|
+
fetch: (sdk) => {
|
|
5
|
+
return concatPaginated({
|
|
6
|
+
sources: [() => sdk.listTables({ owner: "me" }), () => sdk.listTables()],
|
|
7
|
+
dedupe: (table) => table.id,
|
|
8
|
+
});
|
|
9
|
+
},
|
|
10
|
+
prompt: (tables) => ({
|
|
11
|
+
type: "list",
|
|
12
|
+
name: "tableId",
|
|
13
|
+
message: "Select a table:",
|
|
14
|
+
choices: tables.map((table) => ({
|
|
15
|
+
name: `${table.name} (${table.id})`,
|
|
16
|
+
value: table.id,
|
|
17
|
+
})),
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableName.d.ts","sourceRoot":"","sources":["../../src/resolvers/tableName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,eAAO,MAAM,iBAAiB,EAAE,cAI/B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DynamicResolver } from "../utils/schema-utils";
|
|
2
|
+
import type { RecordItem } from "../plugins/tables/getTableRecord/schemas";
|
|
3
|
+
export declare const tableRecordIdResolver: DynamicResolver<RecordItem, {
|
|
4
|
+
tableId: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const tableRecordIdsResolver: DynamicResolver<RecordItem, {
|
|
7
|
+
tableId: string;
|
|
8
|
+
}>;
|
|
9
|
+
//# sourceMappingURL=tableRecordId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableRecordId.d.ts","sourceRoot":"","sources":["../../src/resolvers/tableRecordId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAgC3E,eAAO,MAAM,qBAAqB,EAAE,eAAe,CACjD,UAAU,EACV;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAWpB,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,eAAe,CAClD,UAAU,EACV;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAepB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { formatFieldValue } from "../plugins/tables/utils";
|
|
2
|
+
function summarizeRecord(record) {
|
|
3
|
+
const values = Object.values(record.data);
|
|
4
|
+
const preview = values
|
|
5
|
+
.slice(0, 3)
|
|
6
|
+
.map((v) => formatFieldValue(v).replace(/\s+/g, " ").trim())
|
|
7
|
+
.filter((s) => s.length > 0)
|
|
8
|
+
.join(", ");
|
|
9
|
+
const truncated = preview.length > 60 ? preview.slice(0, 57) + "..." : preview;
|
|
10
|
+
return truncated ? `${record.id} — ${truncated}` : record.id;
|
|
11
|
+
}
|
|
12
|
+
function fetchRecords(sdk, params) {
|
|
13
|
+
return sdk.listTableRecords({
|
|
14
|
+
tableId: params.tableId,
|
|
15
|
+
keyMode: "names",
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function recordChoices(records) {
|
|
19
|
+
return records.map((record) => ({
|
|
20
|
+
name: summarizeRecord(record),
|
|
21
|
+
value: record.id,
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
export const tableRecordIdResolver = {
|
|
25
|
+
type: "dynamic",
|
|
26
|
+
depends: ["tableId"],
|
|
27
|
+
fetch: fetchRecords,
|
|
28
|
+
prompt: (records) => ({
|
|
29
|
+
type: "list",
|
|
30
|
+
name: "recordId",
|
|
31
|
+
message: "Select a record:",
|
|
32
|
+
choices: recordChoices(records),
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
35
|
+
export const tableRecordIdsResolver = {
|
|
36
|
+
type: "dynamic",
|
|
37
|
+
depends: ["tableId"],
|
|
38
|
+
fetch: fetchRecords,
|
|
39
|
+
prompt: (records) => ({
|
|
40
|
+
type: "checkbox",
|
|
41
|
+
name: "recordIds",
|
|
42
|
+
message: "Select records to delete:",
|
|
43
|
+
choices: recordChoices(records),
|
|
44
|
+
validate: (value) => Array.isArray(value) && value.length > 0
|
|
45
|
+
? true
|
|
46
|
+
: "Select at least one record",
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ArrayResolver } from "../utils/schema-utils";
|
|
2
|
+
export declare const tableRecordsResolver: ArrayResolver<{
|
|
3
|
+
tableId: string;
|
|
4
|
+
}>;
|
|
5
|
+
export declare const tableUpdateRecordsResolver: ArrayResolver<{
|
|
6
|
+
tableId: string;
|
|
7
|
+
}>;
|
|
8
|
+
//# sourceMappingURL=tableRecords.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableRecords.d.ts","sourceRoot":"","sources":["../../src/resolvers/tableRecords.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,uBAAuB,CAAC;AAqE3E,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAUnE,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,aAAa,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAWzE,CAAC"}
|