@proofkit/fmdapi 5.0.0-beta.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.
Files changed (49) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +110 -0
  3. package/dist/esm/adapters/core.d.ts +55 -0
  4. package/dist/esm/adapters/fetch-base-types.d.ts +7 -0
  5. package/dist/esm/adapters/fetch-base.d.ts +60 -0
  6. package/dist/esm/adapters/fetch-base.js +256 -0
  7. package/dist/esm/adapters/fetch-base.js.map +1 -0
  8. package/dist/esm/adapters/fetch.d.ts +27 -0
  9. package/dist/esm/adapters/fetch.js +79 -0
  10. package/dist/esm/adapters/fetch.js.map +1 -0
  11. package/dist/esm/adapters/otto.d.ts +26 -0
  12. package/dist/esm/adapters/otto.js +29 -0
  13. package/dist/esm/adapters/otto.js.map +1 -0
  14. package/dist/esm/client-types.d.ts +226 -0
  15. package/dist/esm/client-types.js +41 -0
  16. package/dist/esm/client-types.js.map +1 -0
  17. package/dist/esm/client.d.ts +133 -0
  18. package/dist/esm/client.js +295 -0
  19. package/dist/esm/client.js.map +1 -0
  20. package/dist/esm/index.d.ts +8 -0
  21. package/dist/esm/index.js +16 -0
  22. package/dist/esm/index.js.map +1 -0
  23. package/dist/esm/tokenStore/file.d.ts +3 -0
  24. package/dist/esm/tokenStore/index.d.ts +3 -0
  25. package/dist/esm/tokenStore/memory.d.ts +3 -0
  26. package/dist/esm/tokenStore/memory.js +21 -0
  27. package/dist/esm/tokenStore/memory.js.map +1 -0
  28. package/dist/esm/tokenStore/types.d.ts +8 -0
  29. package/dist/esm/tokenStore/upstash.d.ts +6 -0
  30. package/dist/esm/utils.d.ts +8 -0
  31. package/dist/esm/utils.js +16 -0
  32. package/dist/esm/utils.js.map +1 -0
  33. package/package.json +99 -0
  34. package/src/adapters/core.ts +62 -0
  35. package/src/adapters/fetch-base-types.ts +5 -0
  36. package/src/adapters/fetch-base.ts +339 -0
  37. package/src/adapters/fetch.ts +95 -0
  38. package/src/adapters/otto.ts +59 -0
  39. package/src/client-types.ts +296 -0
  40. package/src/client.ts +534 -0
  41. package/src/index.ts +11 -0
  42. package/src/tokenStore/file.ts +33 -0
  43. package/src/tokenStore/index.ts +3 -0
  44. package/src/tokenStore/memory.ts +20 -0
  45. package/src/tokenStore/types.ts +7 -0
  46. package/src/tokenStore/upstash.ts +31 -0
  47. package/src/utils.ts +29 -0
  48. package/stubs/fmschema.config.stub.js +17 -0
  49. package/stubs/fmschema.config.stub.mjs +17 -0
@@ -0,0 +1,296 @@
1
+ import { z } from "zod";
2
+
3
+ export const ZFieldValue = z.union([
4
+ z.string(),
5
+ z.number(),
6
+ z.null(),
7
+ z.unknown(),
8
+ ]);
9
+ export type FieldValue = z.infer<typeof ZFieldValue>;
10
+
11
+ export const ZFieldData = z.record(z.string(), ZFieldValue);
12
+ export type FieldData = Record<string, unknown>;
13
+
14
+ export type GenericPortalData = {
15
+ [key: string]: {
16
+ [x: string]: string | number | null | unknown;
17
+ };
18
+ };
19
+
20
+ export type PortalsWithIds<U extends GenericPortalData = GenericPortalData> = {
21
+ [key in keyof U]: Array<
22
+ U[key] & {
23
+ recordId: string;
24
+ modId: string;
25
+ }
26
+ >;
27
+ };
28
+ export type UpdatePortalsWithIds<
29
+ U extends GenericPortalData = GenericPortalData,
30
+ > = {
31
+ [key in keyof U]: Array<
32
+ U[key] & {
33
+ recordId: string;
34
+ modId?: string;
35
+ }
36
+ >;
37
+ };
38
+
39
+ export type FMRecord<
40
+ T extends FieldData = FieldData,
41
+ U extends GenericPortalData = GenericPortalData,
42
+ > = {
43
+ fieldData: T;
44
+ recordId: string;
45
+ modId: string;
46
+ portalData: PortalsWithIds<U>;
47
+ };
48
+
49
+ export type ScriptParams = {
50
+ script?: string;
51
+ "script.param"?: string;
52
+ "script.prerequest"?: string;
53
+ "script.prerequest.param"?: string;
54
+ "script.presort"?: string;
55
+ "script.presort.param"?: string;
56
+ timeout?: number;
57
+ };
58
+
59
+ const ZScriptResponse = z.object({
60
+ scriptResult: z.string().optional(),
61
+ scriptError: z.string().optional(),
62
+ "scriptResult.prerequest": z.string().optional(),
63
+ "scriptError.prerequest": z.string().optional(),
64
+ "scriptResult.presort": z.string().optional(),
65
+ "scriptError.presort": z.string().optional(),
66
+ });
67
+ export type ScriptResponse = z.infer<typeof ZScriptResponse>;
68
+
69
+ export const ZDataInfo = z.object({
70
+ database: z.string(),
71
+ layout: z.string(),
72
+ table: z.string(),
73
+ totalRecordCount: z.number(),
74
+ foundCount: z.number(),
75
+ returnedCount: z.number(),
76
+ });
77
+ export type DataInfo = z.infer<typeof ZDataInfo>;
78
+
79
+ export type CreateParams<U extends GenericPortalData = GenericPortalData> =
80
+ ScriptParams & { portalData?: UpdatePortalsWithIds<U> };
81
+
82
+ export type CreateResponse = ScriptResponse & {
83
+ recordId: string;
84
+ modId: string;
85
+ };
86
+
87
+ export type UpdateParams<U extends GenericPortalData = GenericPortalData> =
88
+ CreateParams<U> & {
89
+ modId?: number;
90
+ };
91
+
92
+ export type UpdateResponse = ScriptResponse & {
93
+ modId: string;
94
+ };
95
+
96
+ export type DeleteParams = ScriptParams;
97
+
98
+ export type DeleteResponse = ScriptResponse;
99
+
100
+ export type RangeParams = {
101
+ offset?: number;
102
+ limit?: number;
103
+ };
104
+ export type RangeParamsRaw = {
105
+ _offset?: number;
106
+ _limit?: number;
107
+ };
108
+
109
+ export type PortalRanges<U extends GenericPortalData = GenericPortalData> =
110
+ Partial<{ [key in keyof U]: RangeParams }>;
111
+
112
+ export type PortalRangesParams<
113
+ U extends GenericPortalData = GenericPortalData,
114
+ > = {
115
+ portalRanges?: PortalRanges<U>;
116
+ };
117
+
118
+ export type GetParams<U extends GenericPortalData = GenericPortalData> =
119
+ ScriptParams &
120
+ PortalRangesParams<U> & {
121
+ "layout.response"?: string;
122
+ dateformats?: "US" | "file_locale" | "ISO8601";
123
+ };
124
+
125
+ export type Sort<T extends FieldData = FieldData> = {
126
+ fieldName: keyof T;
127
+ sortOrder?: "ascend" | "descend" | (string & {});
128
+ };
129
+
130
+ export type ListParams<
131
+ T extends FieldData = FieldData,
132
+ U extends GenericPortalData = GenericPortalData,
133
+ > = GetParams<U> &
134
+ RangeParams & {
135
+ sort?: Sort<T> | Array<Sort<T>>;
136
+ };
137
+
138
+ export type ListParamsRaw<
139
+ T extends FieldData = FieldData,
140
+ U extends GenericPortalData = GenericPortalData,
141
+ > = GetParams<U> &
142
+ RangeParamsRaw & {
143
+ _sort?: Array<Sort<T>>;
144
+ };
145
+
146
+ export type GetResponse<
147
+ T extends FieldData = FieldData,
148
+ U extends GenericPortalData = GenericPortalData,
149
+ > = ScriptResponse & {
150
+ data: Array<FMRecord<T, U>>;
151
+ dataInfo: DataInfo;
152
+ };
153
+ export type GetResponseOne<
154
+ T extends FieldData = FieldData,
155
+ U extends GenericPortalData = GenericPortalData,
156
+ > = ScriptResponse & {
157
+ data: FMRecord<T, U>;
158
+ dataInfo: DataInfo;
159
+ };
160
+
161
+ type SecondLevelKeys<T> = {
162
+ [K in keyof T]: keyof T[K];
163
+ }[keyof T];
164
+ export type Query<
165
+ T extends FieldData = FieldData,
166
+ U extends GenericPortalData = GenericPortalData,
167
+ > = Partial<{
168
+ [key in keyof T]: T[key] extends number ? number | string : string;
169
+ }> &
170
+ Partial<{ [key in SecondLevelKeys<U>]?: string }> & {
171
+ omit?: "true";
172
+ };
173
+
174
+ export type LayoutMetadataResponse = {
175
+ fieldMetaData: FieldMetaData[];
176
+ portalMetaData: { [key: string]: FieldMetaData[] };
177
+ valueLists?: ValueList[];
178
+ };
179
+ export type ProductInfoMetadataResponse = {
180
+ name: string;
181
+ dateFormat: string;
182
+ timeFormat: string;
183
+ timeStampFormat: string;
184
+ };
185
+ export type DatabaseMetadataResponse = {
186
+ databases: Array<{
187
+ name: string;
188
+ }>;
189
+ };
190
+
191
+ export type FieldMetaData = {
192
+ name: string;
193
+ type: "normal" | "calculation" | "summary";
194
+ displayType:
195
+ | "editText"
196
+ | "popupList"
197
+ | "popupMenu"
198
+ | "checkBox"
199
+ | "calendar"
200
+ | "radioButtons"
201
+ | "secureText";
202
+ result: "text" | "number" | "date" | "time" | "timeStamp" | "container";
203
+ global: boolean;
204
+ autoEnter: boolean;
205
+ fourDigitYear: boolean;
206
+ maxRepeat: number;
207
+ maxCharacters: number;
208
+ notEmpty: boolean;
209
+ numeric: boolean;
210
+ repetitions: number;
211
+ timeOfDay: boolean;
212
+ valueList?: string;
213
+ };
214
+
215
+ type ValueList = {
216
+ name: string;
217
+ // TODO need to test type of value list from other file
218
+ type: "customList" | "byField";
219
+ values: Array<{ value: string; displayValue: string }>;
220
+ };
221
+
222
+ /**
223
+ * Represents the data returned by a call to the Data API `layouts` endpoint.
224
+ */
225
+ export type AllLayoutsMetadataResponse = {
226
+ /**
227
+ * A list of `Layout` or `LayoutsFolder` objects.
228
+ */
229
+ layouts: LayoutOrFolder[];
230
+ };
231
+
232
+ /**
233
+ * Represents a FileMaker layout.
234
+ */
235
+ export type Layout = {
236
+ /**
237
+ * The name of the layout
238
+ */
239
+ name: string;
240
+ /**
241
+ * If the node is a layout, `table` may contain the name of the table
242
+ * the layout is associated with.
243
+ */
244
+ table: string;
245
+ };
246
+
247
+ /**
248
+ * Represents a folder of `Layout` or `LayoutsFolder` objects.
249
+ */
250
+ export type LayoutsFolder = {
251
+ /**
252
+ * The name of the folder
253
+ */
254
+ name: string;
255
+ isFolder: boolean;
256
+ /**
257
+ * A list of the Layout or LayoutsFolder objects in the folder.
258
+ */
259
+ folderLayoutNames?: LayoutOrFolder[];
260
+ };
261
+
262
+ export type LayoutOrFolder = Layout | LayoutsFolder;
263
+
264
+ /**
265
+ * Represents the data returned by a call to the Data API `scripts` endpoint.
266
+ */
267
+ export type ScriptsMetadataResponse = {
268
+ /**
269
+ * A list of `Layout` or `LayoutsFolder` objects.
270
+ */
271
+ scripts: ScriptOrFolder[];
272
+ };
273
+ type Script = {
274
+ name: string;
275
+ isFolder: false;
276
+ };
277
+ type ScriptFolder = {
278
+ name: string;
279
+ isFolder: true;
280
+ folderScriptNames: ScriptOrFolder[];
281
+ };
282
+ export type ScriptOrFolder = Script | ScriptFolder;
283
+
284
+ export type RawFMResponse<T = unknown> = {
285
+ response?: T;
286
+ messages?: [{ code: string }];
287
+ };
288
+
289
+ export class FileMakerError extends Error {
290
+ public readonly code: string;
291
+
292
+ public constructor(code: string, message: string) {
293
+ super(message);
294
+ this.code = code;
295
+ }
296
+ }