@oblax/forms 1.0.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/dist/entries.d.ts +39 -0
- package/dist/entries.d.ts.map +1 -0
- package/dist/entries.js +66 -0
- package/dist/entries.js.map +1 -0
- package/dist/fields.d.ts +21 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +32 -0
- package/dist/fields.js.map +1 -0
- package/dist/forms-module.d.ts +58 -0
- package/dist/forms-module.d.ts.map +1 -0
- package/dist/forms-module.js +76 -0
- package/dist/forms-module.js.map +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +100 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { OblaxContext } from '@oblax/core';
|
|
2
|
+
import type { CreateEntryParams, EntryIdParams, FormEntry, ListEntriesParams } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Manages entries (submissions) for a form.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // Submit an entry
|
|
9
|
+
* const entry = await oblax.forms.entries.create({
|
|
10
|
+
* formId: 'form-id',
|
|
11
|
+
* data: { first_name: 'John', last_name: 'Doe', age: 30 },
|
|
12
|
+
* })
|
|
13
|
+
*
|
|
14
|
+
* // List all submissions
|
|
15
|
+
* const entries = await oblax.forms.entries.list({ formId: 'form-id' })
|
|
16
|
+
*
|
|
17
|
+
* // Fetch one by ID
|
|
18
|
+
* const one = await oblax.forms.entries.get({ formId: 'form-id', entryId: entry.id })
|
|
19
|
+
*
|
|
20
|
+
* // Delete
|
|
21
|
+
* await oblax.forms.entries.delete({ formId: 'form-id', entryId: entry.id })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class EntriesSubmodule {
|
|
25
|
+
private readonly ctx;
|
|
26
|
+
constructor(ctx: OblaxContext);
|
|
27
|
+
/**
|
|
28
|
+
* Submits a new entry for the given form.
|
|
29
|
+
* `data` must contain keys that match the form's field names.
|
|
30
|
+
*/
|
|
31
|
+
create(params: CreateEntryParams): Promise<FormEntry>;
|
|
32
|
+
/** Returns all submitted entries for a form. */
|
|
33
|
+
list(params: ListEntriesParams): Promise<FormEntry[]>;
|
|
34
|
+
/** Fetches a single entry by its ID. */
|
|
35
|
+
get(params: EntryIdParams): Promise<FormEntry>;
|
|
36
|
+
/** Deletes an entry. */
|
|
37
|
+
delete(params: EntryIdParams): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=entries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entries.d.ts","sourceRoot":"","sources":["../src/entries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EACV,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,iBAAiB,EAClB,MAAM,YAAY,CAAA;AAoBnB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,YAAY;IAE9C;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,CAAC;IAQ3D,gDAAgD;IAC1C,IAAI,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAO3D,wCAAwC;IAClC,GAAG,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC;IAOpD,wBAAwB;IAClB,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAKnD"}
|
package/dist/entries.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collapses a flat API entry object into a typed `FormEntry`.
|
|
3
|
+
*
|
|
4
|
+
* The API returns entries as a flat object where `id` and `form_id` are
|
|
5
|
+
* metadata and every other key is a field value, e.g.:
|
|
6
|
+
* ```json
|
|
7
|
+
* { "id": "abc", "form_id": "xyz", "first_name": "John", "age": 30 }
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
function normalizeEntry(raw) {
|
|
11
|
+
const { id, form_id, ...values } = raw;
|
|
12
|
+
return {
|
|
13
|
+
id: id,
|
|
14
|
+
formId: form_id,
|
|
15
|
+
values,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Manages entries (submissions) for a form.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Submit an entry
|
|
24
|
+
* const entry = await oblax.forms.entries.create({
|
|
25
|
+
* formId: 'form-id',
|
|
26
|
+
* data: { first_name: 'John', last_name: 'Doe', age: 30 },
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* // List all submissions
|
|
30
|
+
* const entries = await oblax.forms.entries.list({ formId: 'form-id' })
|
|
31
|
+
*
|
|
32
|
+
* // Fetch one by ID
|
|
33
|
+
* const one = await oblax.forms.entries.get({ formId: 'form-id', entryId: entry.id })
|
|
34
|
+
*
|
|
35
|
+
* // Delete
|
|
36
|
+
* await oblax.forms.entries.delete({ formId: 'form-id', entryId: entry.id })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export class EntriesSubmodule {
|
|
40
|
+
constructor(ctx) {
|
|
41
|
+
this.ctx = ctx;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Submits a new entry for the given form.
|
|
45
|
+
* `data` must contain keys that match the form's field names.
|
|
46
|
+
*/
|
|
47
|
+
async create(params) {
|
|
48
|
+
const raw = await this.ctx.http.post(`/forms/${params.formId}/entries`, params.data);
|
|
49
|
+
return normalizeEntry(raw);
|
|
50
|
+
}
|
|
51
|
+
/** Returns all submitted entries for a form. */
|
|
52
|
+
async list(params) {
|
|
53
|
+
const raw = await this.ctx.http.get(`/forms/${params.formId}/entries`);
|
|
54
|
+
return raw.map(normalizeEntry);
|
|
55
|
+
}
|
|
56
|
+
/** Fetches a single entry by its ID. */
|
|
57
|
+
async get(params) {
|
|
58
|
+
const raw = await this.ctx.http.get(`/forms/${params.formId}/entries/${params.entryId}`);
|
|
59
|
+
return normalizeEntry(raw);
|
|
60
|
+
}
|
|
61
|
+
/** Deletes an entry. */
|
|
62
|
+
async delete(params) {
|
|
63
|
+
return this.ctx.http.delete(`/forms/${params.formId}/entries/${params.entryId}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=entries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entries.js","sourceRoot":"","sources":["../src/entries.ts"],"names":[],"mappings":"AAQA;;;;;;;;GAQG;AACH,SAAS,cAAc,CAAC,GAA4B;IAClD,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,GAAG,CAAA;IACtC,OAAO;QACL,EAAE,EAAM,EAAY;QACpB,MAAM,EAAE,OAAiB;QACzB,MAAM;KACP,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,gBAAgB;IAC3B,YAA6B,GAAiB;QAAjB,QAAG,GAAH,GAAG,CAAc;IAAG,CAAC;IAElD;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,MAAyB;QACpC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAClC,UAAU,MAAM,CAAC,MAAM,UAAU,EACjC,MAAM,CAAC,IAAI,CACZ,CAAA;QACD,OAAO,cAAc,CAAC,GAAG,CAAC,CAAA;IAC5B,CAAC;IAED,gDAAgD;IAChD,KAAK,CAAC,IAAI,CAAC,MAAyB;QAClC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CACjC,UAAU,MAAM,CAAC,MAAM,UAAU,CAClC,CAAA;QACD,OAAO,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;IAChC,CAAC;IAED,wCAAwC;IACxC,KAAK,CAAC,GAAG,CAAC,MAAqB;QAC7B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CACjC,UAAU,MAAM,CAAC,MAAM,YAAY,MAAM,CAAC,OAAO,EAAE,CACpD,CAAA;QACD,OAAO,cAAc,CAAC,GAAG,CAAC,CAAA;IAC5B,CAAC;IAED,wBAAwB;IACxB,KAAK,CAAC,MAAM,CAAC,MAAqB;QAChC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CACzB,UAAU,MAAM,CAAC,MAAM,YAAY,MAAM,CAAC,OAAO,EAAE,CACpD,CAAA;IACH,CAAC;CACF"}
|
package/dist/fields.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { OblaxContext } from '@oblax/core';
|
|
2
|
+
/**
|
|
3
|
+
* Manages fields within a specific form.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* // Add a field to an existing form
|
|
8
|
+
* const field = await oblax.forms.fields.create({
|
|
9
|
+
* formId: 'form-id',
|
|
10
|
+
* field: { name: 'phone', dataType: 'string', required: false },
|
|
11
|
+
* })
|
|
12
|
+
*
|
|
13
|
+
* // Remove a field
|
|
14
|
+
* await oblax.forms.fields.delete({ formId: 'form-id', fieldId: field.id })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class FieldsSubmodule {
|
|
18
|
+
private readonly ctx;
|
|
19
|
+
constructor(ctx: OblaxContext);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAe/C;;;;;;;;;;;;;;GAcG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,YAAY;CAoB/C"}
|
package/dist/fields.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Maps a `FormFieldDraft` (camelCase input) to the API's snake_case body shape. */
|
|
2
|
+
function draftToApiField(draft) {
|
|
3
|
+
return {
|
|
4
|
+
name: draft.name,
|
|
5
|
+
data_type: draft.dataType,
|
|
6
|
+
required: draft.required,
|
|
7
|
+
options: draft.options ?? null,
|
|
8
|
+
depends_field: draft.dependsField ?? '',
|
|
9
|
+
depends_field_value: draft.dependsFieldValue ?? '',
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Manages fields within a specific form.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Add a field to an existing form
|
|
18
|
+
* const field = await oblax.forms.fields.create({
|
|
19
|
+
* formId: 'form-id',
|
|
20
|
+
* field: { name: 'phone', dataType: 'string', required: false },
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* // Remove a field
|
|
24
|
+
* await oblax.forms.fields.delete({ formId: 'form-id', fieldId: field.id })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export class FieldsSubmodule {
|
|
28
|
+
constructor(ctx) {
|
|
29
|
+
this.ctx = ctx;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAGA,oFAAoF;AACpF,SAAS,eAAe,CAAC,KAAqB;IAC5C,OAAO;QACL,IAAI,EAAiB,KAAK,CAAC,IAAI;QAC/B,SAAS,EAAY,KAAK,CAAC,QAAQ;QACnC,QAAQ,EAAa,KAAK,CAAC,QAAQ;QACnC,OAAO,EAAc,KAAK,CAAC,OAAO,IAAI,IAAI;QAC1C,aAAa,EAAQ,KAAK,CAAC,YAAY,IAAI,EAAE;QAC7C,mBAAmB,EAAE,KAAK,CAAC,iBAAiB,IAAI,EAAE;KACnD,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,eAAe;IAC1B,YAA6B,GAAiB;QAAjB,QAAG,GAAH,GAAG,CAAc;IAAG,CAAC;CAoBnD"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { OblaxContext } from '@oblax/core';
|
|
2
|
+
import type { CreateFormParams, Form, FormIdParams, FormsConfig } from './types.js';
|
|
3
|
+
import { FieldsSubmodule } from './fields.js';
|
|
4
|
+
import { EntriesSubmodule } from './entries.js';
|
|
5
|
+
/**
|
|
6
|
+
* The Forms module.
|
|
7
|
+
*
|
|
8
|
+
* Provides CRUD for form definitions directly on the module, with
|
|
9
|
+
* `fields` and `entries` exposed as sub-modules for their nested resources.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const oblax = new Oblax({
|
|
14
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
15
|
+
* clientId: 'my-web-app',
|
|
16
|
+
* modules: [PlatformBrowser(), Forms()],
|
|
17
|
+
* })
|
|
18
|
+
*
|
|
19
|
+
* // Manage form definitions
|
|
20
|
+
* const form = await oblax.forms.create({
|
|
21
|
+
* name: 'Contact',
|
|
22
|
+
* fields: [
|
|
23
|
+
* { name: 'email', dataType: 'string', required: true },
|
|
24
|
+
* { name: 'message', dataType: 'string', required: true },
|
|
25
|
+
* ],
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* // Submit an entry
|
|
29
|
+
* await oblax.forms.entries.create({
|
|
30
|
+
* formId: form.id,
|
|
31
|
+
* data: { email: 'alice@example.com', message: 'Hello!' },
|
|
32
|
+
* })
|
|
33
|
+
*
|
|
34
|
+
* // Add a field after creation
|
|
35
|
+
* await oblax.forms.fields.create({
|
|
36
|
+
* formId: form.id,
|
|
37
|
+
* field: { name: 'phone', dataType: 'string', required: false },
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class FormsModule {
|
|
42
|
+
private readonly ctx;
|
|
43
|
+
/** Manages fields within a form. */
|
|
44
|
+
readonly fields: FieldsSubmodule;
|
|
45
|
+
/** Manages entries (submissions) for a form. */
|
|
46
|
+
readonly entries: EntriesSubmodule;
|
|
47
|
+
constructor(ctx: OblaxContext, _config: FormsConfig);
|
|
48
|
+
/** Returns all form definitions. */
|
|
49
|
+
list(): Promise<Form[]>;
|
|
50
|
+
/** Fetches a single form definition by ID. */
|
|
51
|
+
get(params: FormIdParams): Promise<Form>;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a new form with the given name and initial field definitions.
|
|
54
|
+
* Returns the created form including assigned IDs for each field.
|
|
55
|
+
*/
|
|
56
|
+
create(params: CreateFormParams): Promise<Form>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=forms-module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forms-module.d.ts","sourceRoot":"","sources":["../src/forms-module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EACV,gBAAgB,EAChB,IAAI,EAEJ,YAAY,EACZ,WAAW,EAEZ,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAc/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,WAAW;IAMV,OAAO,CAAC,QAAQ,CAAC,GAAG;IALhC,oCAAoC;IACpC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;IAChC,gDAAgD;IAChD,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAA;gBAEL,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW;IAOpE,oCAAoC;IAC9B,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAI7B,8CAA8C;IACxC,GAAG,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;CAyBtD"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { FieldsSubmodule } from './fields.js';
|
|
2
|
+
import { EntriesSubmodule } from './entries.js';
|
|
3
|
+
/** Maps a `FormFieldDraft` to the API's snake_case body shape. */
|
|
4
|
+
function draftToApiField(draft) {
|
|
5
|
+
return {
|
|
6
|
+
name: draft.name,
|
|
7
|
+
data_type: draft.dataType,
|
|
8
|
+
required: draft.required,
|
|
9
|
+
options: draft.options ?? null,
|
|
10
|
+
depends_field: draft.dependsField ?? '',
|
|
11
|
+
depends_field_value: draft.dependsFieldValue ?? '',
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The Forms module.
|
|
16
|
+
*
|
|
17
|
+
* Provides CRUD for form definitions directly on the module, with
|
|
18
|
+
* `fields` and `entries` exposed as sub-modules for their nested resources.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const oblax = new Oblax({
|
|
23
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
24
|
+
* clientId: 'my-web-app',
|
|
25
|
+
* modules: [PlatformBrowser(), Forms()],
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* // Manage form definitions
|
|
29
|
+
* const form = await oblax.forms.create({
|
|
30
|
+
* name: 'Contact',
|
|
31
|
+
* fields: [
|
|
32
|
+
* { name: 'email', dataType: 'string', required: true },
|
|
33
|
+
* { name: 'message', dataType: 'string', required: true },
|
|
34
|
+
* ],
|
|
35
|
+
* })
|
|
36
|
+
*
|
|
37
|
+
* // Submit an entry
|
|
38
|
+
* await oblax.forms.entries.create({
|
|
39
|
+
* formId: form.id,
|
|
40
|
+
* data: { email: 'alice@example.com', message: 'Hello!' },
|
|
41
|
+
* })
|
|
42
|
+
*
|
|
43
|
+
* // Add a field after creation
|
|
44
|
+
* await oblax.forms.fields.create({
|
|
45
|
+
* formId: form.id,
|
|
46
|
+
* field: { name: 'phone', dataType: 'string', required: false },
|
|
47
|
+
* })
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export class FormsModule {
|
|
51
|
+
constructor(ctx, _config) {
|
|
52
|
+
this.ctx = ctx;
|
|
53
|
+
this.fields = new FieldsSubmodule(ctx);
|
|
54
|
+
this.entries = new EntriesSubmodule(ctx);
|
|
55
|
+
}
|
|
56
|
+
// ─── Form CRUD ─────────────────────────────────────────────────────────────
|
|
57
|
+
/** Returns all form definitions. */
|
|
58
|
+
async list() {
|
|
59
|
+
return this.ctx.http.get('/forms');
|
|
60
|
+
}
|
|
61
|
+
/** Fetches a single form definition by ID. */
|
|
62
|
+
async get(params) {
|
|
63
|
+
return this.ctx.http.get(`/forms/${params.id}`);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Creates a new form with the given name and initial field definitions.
|
|
67
|
+
* Returns the created form including assigned IDs for each field.
|
|
68
|
+
*/
|
|
69
|
+
async create(params) {
|
|
70
|
+
return this.ctx.http.post('/forms', {
|
|
71
|
+
name: params.name,
|
|
72
|
+
fields: params.fields.map(draftToApiField),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=forms-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|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QAAQ,EAAE;YACxC,IAAI,EAAI,MAAM,CAAC,IAAI;YACnB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC;SAC3C,CAAC,CAAA;IACJ,CAAC;CAoBF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { OblaxModulePlugin } from '@oblax/core';
|
|
2
|
+
import { FormsModule } from './forms-module.js';
|
|
3
|
+
import type { FormsConfig } from './types.js';
|
|
4
|
+
export { FormsModule } from './forms-module.js';
|
|
5
|
+
export { FieldsSubmodule } from './fields.js';
|
|
6
|
+
export { EntriesSubmodule } from './entries.js';
|
|
7
|
+
export type { FormsConfig, Form, CreateFormParams, UpdateFormParams, FormIdParams, FormField, FormFieldDraft, AddFieldParams, DeleteFieldParams, FormEntry, CreateEntryParams, ListEntriesParams, EntryIdParams, } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Forms module factory.
|
|
10
|
+
*
|
|
11
|
+
* Registers the forms module with the Oblax SDK. Form CRUD operations are
|
|
12
|
+
* available directly on `oblax.forms`; field and entry operations are exposed
|
|
13
|
+
* via `oblax.forms.fields` and `oblax.forms.entries`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { Oblax } from '@oblax/core'
|
|
18
|
+
* import { PlatformBrowser } from '@oblax/platform-browser'
|
|
19
|
+
* import { Forms } from '@oblax/forms'
|
|
20
|
+
*
|
|
21
|
+
* const oblax = new Oblax({
|
|
22
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
23
|
+
* clientId: 'my-web-app',
|
|
24
|
+
* modules: [PlatformBrowser(), Forms()],
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* // Form definitions
|
|
28
|
+
* const form = await oblax.forms.create({
|
|
29
|
+
* name: 'Feedback',
|
|
30
|
+
* fields: [
|
|
31
|
+
* { name: 'email', dataType: 'string', required: true },
|
|
32
|
+
* { name: 'rating', dataType: 'int', required: true },
|
|
33
|
+
* { name: 'comment', dataType: 'string', required: false },
|
|
34
|
+
* ],
|
|
35
|
+
* })
|
|
36
|
+
*
|
|
37
|
+
* // Submit an entry
|
|
38
|
+
* const entry = await oblax.forms.entries.create({
|
|
39
|
+
* formId: form.id,
|
|
40
|
+
* data: { email: 'alice@example.com', rating: 5, comment: 'Great!' },
|
|
41
|
+
* })
|
|
42
|
+
*
|
|
43
|
+
* // List submissions
|
|
44
|
+
* const all = await oblax.forms.entries.list({ formId: form.id })
|
|
45
|
+
*
|
|
46
|
+
* // Add a field after the fact
|
|
47
|
+
* await oblax.forms.fields.create({
|
|
48
|
+
* formId: form.id,
|
|
49
|
+
* field: { name: 'phone', dataType: 'string', required: false },
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function Forms(config?: FormsConfig): OblaxModulePlugin<'forms', FormsModule>;
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAE/C,YAAY,EACV,WAAW,EAEX,IAAI,EACJ,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EAEZ,SAAS,EACT,cAAc,EACd,cAAc,EACd,iBAAiB,EAEjB,SAAS,EACT,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,GACd,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,KAAK,CAAC,MAAM,GAAE,WAAgB,GAAG,iBAAiB,CAAC,OAAO,EAAE,WAAW,CAAC,CAOvF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { FormsModule } from './forms-module.js';
|
|
2
|
+
export { FormsModule } from './forms-module.js';
|
|
3
|
+
export { FieldsSubmodule } from './fields.js';
|
|
4
|
+
export { EntriesSubmodule } from './entries.js';
|
|
5
|
+
/**
|
|
6
|
+
* Forms module factory.
|
|
7
|
+
*
|
|
8
|
+
* Registers the forms module with the Oblax SDK. Form CRUD operations are
|
|
9
|
+
* available directly on `oblax.forms`; field and entry operations are exposed
|
|
10
|
+
* via `oblax.forms.fields` and `oblax.forms.entries`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { Oblax } from '@oblax/core'
|
|
15
|
+
* import { PlatformBrowser } from '@oblax/platform-browser'
|
|
16
|
+
* import { Forms } from '@oblax/forms'
|
|
17
|
+
*
|
|
18
|
+
* const oblax = new Oblax({
|
|
19
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
20
|
+
* clientId: 'my-web-app',
|
|
21
|
+
* modules: [PlatformBrowser(), Forms()],
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* // Form definitions
|
|
25
|
+
* const form = await oblax.forms.create({
|
|
26
|
+
* name: 'Feedback',
|
|
27
|
+
* fields: [
|
|
28
|
+
* { name: 'email', dataType: 'string', required: true },
|
|
29
|
+
* { name: 'rating', dataType: 'int', required: true },
|
|
30
|
+
* { name: 'comment', dataType: 'string', required: false },
|
|
31
|
+
* ],
|
|
32
|
+
* })
|
|
33
|
+
*
|
|
34
|
+
* // Submit an entry
|
|
35
|
+
* const entry = await oblax.forms.entries.create({
|
|
36
|
+
* formId: form.id,
|
|
37
|
+
* data: { email: 'alice@example.com', rating: 5, comment: 'Great!' },
|
|
38
|
+
* })
|
|
39
|
+
*
|
|
40
|
+
* // List submissions
|
|
41
|
+
* const all = await oblax.forms.entries.list({ formId: form.id })
|
|
42
|
+
*
|
|
43
|
+
* // Add a field after the fact
|
|
44
|
+
* await oblax.forms.fields.create({
|
|
45
|
+
* formId: form.id,
|
|
46
|
+
* field: { name: 'phone', dataType: 'string', required: false },
|
|
47
|
+
* })
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function Forms(config = {}) {
|
|
51
|
+
return {
|
|
52
|
+
name: 'forms',
|
|
53
|
+
create(ctx) {
|
|
54
|
+
return new FormsModule(ctx, config);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAqB/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,UAAU,KAAK,CAAC,SAAsB,EAAE;IAC5C,OAAO;QACL,IAAI,EAAE,OAAO;QACb,MAAM,CAAC,GAAiB;YACtB,OAAO,IAAI,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACrC,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A form field as returned by the API.
|
|
3
|
+
* Field names are snake_case to match the wire format exactly.
|
|
4
|
+
*/
|
|
5
|
+
export interface FormField {
|
|
6
|
+
id: string;
|
|
7
|
+
form_id: string;
|
|
8
|
+
/** `true` when the field has been soft-deleted. */
|
|
9
|
+
_deleted: boolean;
|
|
10
|
+
name: string;
|
|
11
|
+
/** Scalar data type, e.g. `'string'`, `'int'`, `'float'`, `'bool'`. */
|
|
12
|
+
data_type: string;
|
|
13
|
+
required: boolean;
|
|
14
|
+
/** Allowed values for enum-style fields. `null` when unconstrained. */
|
|
15
|
+
options: string[] | null;
|
|
16
|
+
/** Name of another field this field depends on. Empty string when unused. */
|
|
17
|
+
depends_field: string;
|
|
18
|
+
/** Value the `depends_field` must have to activate this field. */
|
|
19
|
+
depends_field_value: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Input shape for a new field that does not yet have an `id` or `form_id`.
|
|
23
|
+
* Uses camelCase for JS ergonomics; mapped to snake_case before sending.
|
|
24
|
+
*/
|
|
25
|
+
export interface FormFieldDraft {
|
|
26
|
+
name: string;
|
|
27
|
+
/** Scalar data type, e.g. `'string'`, `'int'`, `'float'`, `'bool'`. */
|
|
28
|
+
dataType: string;
|
|
29
|
+
required: boolean;
|
|
30
|
+
/** Allowed values. Pass `null` or omit for free-form fields. */
|
|
31
|
+
options?: string[] | null;
|
|
32
|
+
/** Name of another field this field depends on. */
|
|
33
|
+
dependsField?: string;
|
|
34
|
+
/** Value the `dependsField` must have to activate this field. */
|
|
35
|
+
dependsFieldValue?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface Form {
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
fields: FormField[];
|
|
41
|
+
}
|
|
42
|
+
export interface CreateFormParams {
|
|
43
|
+
name: string;
|
|
44
|
+
fields: FormFieldDraft[];
|
|
45
|
+
}
|
|
46
|
+
export interface UpdateFormParams {
|
|
47
|
+
/** ID of the form to update. */
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
/**
|
|
51
|
+
* Full field list, typically the `fields` array from a prior `get()` call,
|
|
52
|
+
* optionally with entries modified, added (without `id`), or `_deleted: true`.
|
|
53
|
+
*/
|
|
54
|
+
fields: FormField[];
|
|
55
|
+
}
|
|
56
|
+
export interface FormIdParams {
|
|
57
|
+
id: string;
|
|
58
|
+
}
|
|
59
|
+
export interface AddFieldParams {
|
|
60
|
+
/** ID of the form to add the field to. */
|
|
61
|
+
formId: string;
|
|
62
|
+
field: FormFieldDraft;
|
|
63
|
+
}
|
|
64
|
+
export interface DeleteFieldParams {
|
|
65
|
+
/** ID of the form. */
|
|
66
|
+
formId: string;
|
|
67
|
+
/** ID of the field to delete. */
|
|
68
|
+
fieldId: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A normalised form entry.
|
|
72
|
+
* The raw API response is a flat object whose keys are field names plus `id`
|
|
73
|
+
* and `form_id`. The SDK separates metadata from field values.
|
|
74
|
+
*/
|
|
75
|
+
export interface FormEntry {
|
|
76
|
+
id: string;
|
|
77
|
+
formId: string;
|
|
78
|
+
/** Field-name → value pairs (all keys except `id` and `form_id`). */
|
|
79
|
+
values: Record<string, unknown>;
|
|
80
|
+
}
|
|
81
|
+
export interface CreateEntryParams {
|
|
82
|
+
/** ID of the form to submit an entry for. */
|
|
83
|
+
formId: string;
|
|
84
|
+
/**
|
|
85
|
+
* Field-name → value map that satisfies the form's schema.
|
|
86
|
+
* Keys must match the `name` of the form's fields.
|
|
87
|
+
*/
|
|
88
|
+
data: Record<string, unknown>;
|
|
89
|
+
}
|
|
90
|
+
export interface ListEntriesParams {
|
|
91
|
+
formId: string;
|
|
92
|
+
}
|
|
93
|
+
export interface EntryIdParams {
|
|
94
|
+
formId: string;
|
|
95
|
+
entryId: string;
|
|
96
|
+
}
|
|
97
|
+
/** Forms module configuration. Reserved for future options. */
|
|
98
|
+
export interface FormsConfig {
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],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E,MAAM,CAAA;IACd,KAAK,EAAE,cAAc,CAAA;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,iCAAiC;IACjC,OAAO,EAAE,MAAM,CAAA;CAChB;AAID;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAChC;AAED,MAAM,WAAW,iBAAiB;IAChC,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CAChB;AAID,+DAA+D;AAC/D,MAAM,WAAW,WAAW;CAE3B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,gFAAgF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oblax/forms",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Oblax SDK — forms module (form definitions, fields, entries)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Oblax SDK for JavaScript Team",
|
|
8
|
+
"url": "https://docs.oblax.io/docs/getting-started/your-first-sdk-call"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/oblaxio/oblax-sdk-js#readme",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/oblaxio/oblax-sdk-js.git",
|
|
14
|
+
"directory": "packages/forms"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/oblaxio/oblax-sdk-js/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"oblax",
|
|
21
|
+
"sdk",
|
|
22
|
+
"forms"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@oblax/core": "1.0.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"typescript": "^5.5.0",
|
|
44
|
+
"@oblax/core": "1.0.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsc --build tsconfig.json",
|
|
48
|
+
"typecheck": "tsc --build tsconfig.json --dry",
|
|
49
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
50
|
+
}
|
|
51
|
+
}
|