@evanschleret/formforgeclient 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.
Files changed (121) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +94 -0
  3. package/dist/module.cjs +112 -0
  4. package/dist/module.d.cts +20 -0
  5. package/dist/module.d.mts +20 -0
  6. package/dist/module.d.ts +20 -0
  7. package/dist/module.json +12 -0
  8. package/dist/module.mjs +109 -0
  9. package/dist/runtime/api/categories.d.ts +9 -0
  10. package/dist/runtime/api/categories.js +83 -0
  11. package/dist/runtime/api/client.d.ts +45 -0
  12. package/dist/runtime/api/client.js +148 -0
  13. package/dist/runtime/api/drafts.d.ts +6 -0
  14. package/dist/runtime/api/drafts.js +77 -0
  15. package/dist/runtime/api/http.d.ts +3 -0
  16. package/dist/runtime/api/http.js +138 -0
  17. package/dist/runtime/api/index.d.ts +9 -0
  18. package/dist/runtime/api/index.js +11 -0
  19. package/dist/runtime/api/management.d.ts +19 -0
  20. package/dist/runtime/api/management.js +180 -0
  21. package/dist/runtime/api/request.d.ts +8 -0
  22. package/dist/runtime/api/request.js +52 -0
  23. package/dist/runtime/api/responses.d.ts +6 -0
  24. package/dist/runtime/api/responses.js +61 -0
  25. package/dist/runtime/api/schema.d.ts +7 -0
  26. package/dist/runtime/api/schema.js +56 -0
  27. package/dist/runtime/api/submission.d.ts +11 -0
  28. package/dist/runtime/api/submission.js +47 -0
  29. package/dist/runtime/api/upload.d.ts +8 -0
  30. package/dist/runtime/api/upload.js +37 -0
  31. package/dist/runtime/composables/index.d.ts +31 -0
  32. package/dist/runtime/composables/index.js +16 -0
  33. package/dist/runtime/composables/useFormForgeApi.d.ts +3 -0
  34. package/dist/runtime/composables/useFormForgeApi.js +4 -0
  35. package/dist/runtime/composables/useFormForgeBuilder.d.ts +57 -0
  36. package/dist/runtime/composables/useFormForgeBuilder.js +515 -0
  37. package/dist/runtime/composables/useFormForgeCategory.d.ts +61 -0
  38. package/dist/runtime/composables/useFormForgeCategory.js +248 -0
  39. package/dist/runtime/composables/useFormForgeClient.d.ts +3 -0
  40. package/dist/runtime/composables/useFormForgeClient.js +200 -0
  41. package/dist/runtime/composables/useFormForgeDrafts.d.ts +20 -0
  42. package/dist/runtime/composables/useFormForgeDrafts.js +78 -0
  43. package/dist/runtime/composables/useFormForgeForm.d.ts +26 -0
  44. package/dist/runtime/composables/useFormForgeForm.js +114 -0
  45. package/dist/runtime/composables/useFormForgeGetForm.d.ts +22 -0
  46. package/dist/runtime/composables/useFormForgeGetForm.js +36 -0
  47. package/dist/runtime/composables/useFormForgeI18n.d.ts +250 -0
  48. package/dist/runtime/composables/useFormForgeI18n.js +324 -0
  49. package/dist/runtime/composables/useFormForgeManagement.d.ts +40 -0
  50. package/dist/runtime/composables/useFormForgeManagement.js +153 -0
  51. package/dist/runtime/composables/useFormForgeResolver.d.ts +28 -0
  52. package/dist/runtime/composables/useFormForgeResolver.js +88 -0
  53. package/dist/runtime/composables/useFormForgeResponses.d.ts +45 -0
  54. package/dist/runtime/composables/useFormForgeResponses.js +206 -0
  55. package/dist/runtime/composables/useFormForgeSchema.d.ts +24 -0
  56. package/dist/runtime/composables/useFormForgeSchema.js +69 -0
  57. package/dist/runtime/composables/useFormForgeSubmission.d.ts +12 -0
  58. package/dist/runtime/composables/useFormForgeSubmission.js +4 -0
  59. package/dist/runtime/composables/useFormForgeSubmit.d.ts +29 -0
  60. package/dist/runtime/composables/useFormForgeSubmit.js +291 -0
  61. package/dist/runtime/composables/useFormForgeUploads.d.ts +21 -0
  62. package/dist/runtime/composables/useFormForgeUploads.js +37 -0
  63. package/dist/runtime/composables/useFormForgeWizard.d.ts +20 -0
  64. package/dist/runtime/composables/useFormForgeWizard.js +83 -0
  65. package/dist/runtime/index.d.ts +11 -0
  66. package/dist/runtime/index.js +14 -0
  67. package/dist/runtime/plugin.d.ts +3 -0
  68. package/dist/runtime/plugin.js +175 -0
  69. package/dist/runtime/renderers/default/FormForgeBuilder.d.vue.ts +40 -0
  70. package/dist/runtime/renderers/default/FormForgeBuilder.vue +1159 -0
  71. package/dist/runtime/renderers/default/FormForgeBuilder.vue.d.ts +40 -0
  72. package/dist/runtime/renderers/default/FormForgeCategoryCreateModal.d.vue.ts +16 -0
  73. package/dist/runtime/renderers/default/FormForgeCategoryCreateModal.vue +129 -0
  74. package/dist/runtime/renderers/default/FormForgeCategoryCreateModal.vue.d.ts +16 -0
  75. package/dist/runtime/renderers/default/FormForgeRenderer.d.vue.ts +72 -0
  76. package/dist/runtime/renderers/default/FormForgeRenderer.vue +1188 -0
  77. package/dist/runtime/renderers/default/FormForgeRenderer.vue.d.ts +72 -0
  78. package/dist/runtime/renderers/default/FormForgeResponse.d.vue.ts +18 -0
  79. package/dist/runtime/renderers/default/FormForgeResponse.vue +744 -0
  80. package/dist/runtime/renderers/default/FormForgeResponse.vue.d.ts +18 -0
  81. package/dist/runtime/renderers/default/index.d.ts +5 -0
  82. package/dist/runtime/renderers/default/index.js +4 -0
  83. package/dist/runtime/renderers/index.d.ts +2 -0
  84. package/dist/runtime/renderers/index.js +1 -0
  85. package/dist/runtime/types/api.d.ts +129 -0
  86. package/dist/runtime/types/api.js +0 -0
  87. package/dist/runtime/types/category.d.ts +42 -0
  88. package/dist/runtime/types/category.js +0 -0
  89. package/dist/runtime/types/errors.d.ts +16 -0
  90. package/dist/runtime/types/errors.js +0 -0
  91. package/dist/runtime/types/index.d.ts +8 -0
  92. package/dist/runtime/types/index.js +0 -0
  93. package/dist/runtime/types/json.d.ts +6 -0
  94. package/dist/runtime/types/json.js +0 -0
  95. package/dist/runtime/types/management.d.ts +46 -0
  96. package/dist/runtime/types/management.js +0 -0
  97. package/dist/runtime/types/nuxt.d.ts +13 -0
  98. package/dist/runtime/types/nuxt.js +1 -0
  99. package/dist/runtime/types/schema.d.ts +93 -0
  100. package/dist/runtime/types/schema.js +0 -0
  101. package/dist/runtime/utils/category.d.ts +5 -0
  102. package/dist/runtime/utils/category.js +101 -0
  103. package/dist/runtime/utils/form-data.d.ts +8 -0
  104. package/dist/runtime/utils/form-data.js +64 -0
  105. package/dist/runtime/utils/object.d.ts +8 -0
  106. package/dist/runtime/utils/object.js +43 -0
  107. package/dist/runtime/utils/schema.d.ts +3 -0
  108. package/dist/runtime/utils/schema.js +309 -0
  109. package/dist/runtime/utils/submission.d.ts +4 -0
  110. package/dist/runtime/utils/submission.js +45 -0
  111. package/dist/runtime/validation/errors.d.ts +5 -0
  112. package/dist/runtime/validation/errors.js +130 -0
  113. package/dist/runtime/validation/zod.d.ts +6 -0
  114. package/dist/runtime/validation/zod.js +203 -0
  115. package/dist/runtime.cjs +16 -0
  116. package/dist/runtime.d.cts +1 -0
  117. package/dist/runtime.d.mts +1 -0
  118. package/dist/runtime.d.ts +1 -0
  119. package/dist/runtime.mjs +1 -0
  120. package/dist/types.d.mts +3 -0
  121. package/package.json +60 -0
@@ -0,0 +1,148 @@
1
+ import { createFormForgeHttpAdapter } from "./http.js";
2
+ import { deleteCurrentFormForgeDraft, fetchCurrentFormForgeDraft, saveFormForgeDraft } from "./drafts.js";
3
+ import { fetchFormForgeDiff, fetchFormForgeForms, fetchFormForgeRevisions, createFormForgeForm, deleteFormForgeForm, patchFormForgeForm, publishFormForgeForm, unpublishFormForgeForm } from "./management.js";
4
+ import { createFormForgeCategory, deleteFormForgeCategory, fetchFormForgeCategories, fetchFormForgeCategory, patchFormForgeCategory } from "./categories.js";
5
+ import { fetchFormForgeSchema, fetchFormForgeSchemaVersion, fetchFormForgeSchemaVersions, resolveFormForgeSchema } from "./schema.js";
6
+ import { deleteFormForgeResponse, fetchFormForgeResponse, fetchFormForgeResponses } from "./responses.js";
7
+ import { submitFormForgeJson, submitFormForgeMultipart } from "./submission.js";
8
+ import { stageFormForgeUpload } from "./upload.js";
9
+ class FormForgeClientImpl {
10
+ config;
11
+ http;
12
+ constructor(config = {}) {
13
+ this.config = {
14
+ ...config
15
+ };
16
+ this.http = createFormForgeHttpAdapter(this.config);
17
+ }
18
+ resolveScopeParams(input) {
19
+ if (input === void 0) {
20
+ return {};
21
+ }
22
+ if (typeof input === "function") {
23
+ return input();
24
+ }
25
+ return input;
26
+ }
27
+ resolveNamedScope(name) {
28
+ const scopedRoutes = this.config.scopedRoutes ?? {};
29
+ const routeDefinition = scopedRoutes[name];
30
+ if (routeDefinition === void 0) {
31
+ throw new Error(`Unknown FormForge scope "${name}"`);
32
+ }
33
+ const sourceParams = this.resolveScopeParams(this.config.scopeParams);
34
+ const params = {};
35
+ for (const [scopeParam, sourceParam] of Object.entries(routeDefinition.paramsFromRoute)) {
36
+ const value = sourceParams[sourceParam];
37
+ if (value === void 0 || value === "") {
38
+ throw new Error(`Missing scope param source "${sourceParam}" for named scope "${name}"`);
39
+ }
40
+ params[scopeParam] = value;
41
+ }
42
+ return {
43
+ prefix: routeDefinition.prefix,
44
+ params
45
+ };
46
+ }
47
+ resolveRequestScope(scope) {
48
+ const targetScope = scope ?? this.config.defaultScope;
49
+ if (targetScope === void 0) {
50
+ return void 0;
51
+ }
52
+ if (typeof targetScope === "string") {
53
+ return this.resolveNamedScope(targetScope);
54
+ }
55
+ return targetScope;
56
+ }
57
+ withRequestScope(options) {
58
+ const resolvedScope = this.resolveRequestScope(options.scope);
59
+ if (resolvedScope === void 0) {
60
+ return options;
61
+ }
62
+ return {
63
+ ...options,
64
+ scope: resolvedScope
65
+ };
66
+ }
67
+ async getForm(key, options = {}) {
68
+ return fetchFormForgeSchema(this.http, key, this.withRequestScope(options));
69
+ }
70
+ async getFormVersions(key, options = {}) {
71
+ return fetchFormForgeSchemaVersions(this.http, key, this.withRequestScope(options));
72
+ }
73
+ async getFormVersion(key, version, options = {}) {
74
+ return fetchFormForgeSchemaVersion(this.http, key, version, this.withRequestScope(options));
75
+ }
76
+ async resolveForm(key, input = {}, options = {}) {
77
+ return resolveFormForgeSchema(this.http, key, input, options.version, this.withRequestScope(options));
78
+ }
79
+ async submitForm(key, input, options = {}) {
80
+ return submitFormForgeJson(this.http, key, input, this.withRequestScope(options));
81
+ }
82
+ async submitFormMultipart(key, formData, options = {}) {
83
+ return submitFormForgeMultipart(this.http, key, formData, this.withRequestScope(options));
84
+ }
85
+ async stageUpload(key, input, options = {}) {
86
+ return stageFormForgeUpload(this.http, key, input, this.withRequestScope(options));
87
+ }
88
+ async saveDraft(key, input, options = {}) {
89
+ return saveFormForgeDraft(this.http, key, input, this.withRequestScope(options));
90
+ }
91
+ async getCurrentDraft(key, options = {}) {
92
+ return fetchCurrentFormForgeDraft(this.http, key, this.withRequestScope(options));
93
+ }
94
+ async deleteCurrentDraft(key, options = {}) {
95
+ return deleteCurrentFormForgeDraft(this.http, key, this.withRequestScope(options));
96
+ }
97
+ async listResponses(key, query = {}, options = {}) {
98
+ return fetchFormForgeResponses(this.http, key, query, this.withRequestScope(options));
99
+ }
100
+ async getResponse(key, submissionId, options = {}) {
101
+ return fetchFormForgeResponse(this.http, key, submissionId, this.withRequestScope(options));
102
+ }
103
+ async deleteResponse(key, submissionId, options = {}) {
104
+ return deleteFormForgeResponse(this.http, key, submissionId, this.withRequestScope(options));
105
+ }
106
+ async listForms(includeDeleted = false, options = {}) {
107
+ return fetchFormForgeForms(this.http, includeDeleted, this.withRequestScope(options));
108
+ }
109
+ async createForm(input, options = {}) {
110
+ return createFormForgeForm(this.http, input, this.withRequestScope(options));
111
+ }
112
+ async patchForm(key, input, options = {}) {
113
+ return patchFormForgeForm(this.http, key, input, this.withRequestScope(options));
114
+ }
115
+ async publishForm(key, options = {}) {
116
+ return publishFormForgeForm(this.http, key, this.withRequestScope(options));
117
+ }
118
+ async unpublishForm(key, options = {}) {
119
+ return unpublishFormForgeForm(this.http, key, this.withRequestScope(options));
120
+ }
121
+ async deleteForm(key, options = {}) {
122
+ return deleteFormForgeForm(this.http, key, this.withRequestScope(options));
123
+ }
124
+ async getRevisions(key, includeDeleted = false, options = {}) {
125
+ return fetchFormForgeRevisions(this.http, key, includeDeleted, this.withRequestScope(options));
126
+ }
127
+ async getDiff(key, fromVersion, toVersion, options = {}) {
128
+ return fetchFormForgeDiff(this.http, key, fromVersion, toVersion, this.withRequestScope(options));
129
+ }
130
+ async listCategories(query = {}, options = {}) {
131
+ return fetchFormForgeCategories(this.http, query, this.withRequestScope(options));
132
+ }
133
+ async getCategory(categoryKey, options = {}) {
134
+ return fetchFormForgeCategory(this.http, categoryKey, this.withRequestScope(options));
135
+ }
136
+ async createCategory(input, options = {}) {
137
+ return createFormForgeCategory(this.http, input, this.withRequestScope(options));
138
+ }
139
+ async patchCategory(categoryKey, input, options = {}) {
140
+ return patchFormForgeCategory(this.http, categoryKey, input, this.withRequestScope(options));
141
+ }
142
+ async deleteCategory(categoryKey, options = {}) {
143
+ return deleteFormForgeCategory(this.http, categoryKey, this.withRequestScope(options));
144
+ }
145
+ }
146
+ export function createFormForgeClient(config = {}) {
147
+ return new FormForgeClientImpl(config);
148
+ }
@@ -0,0 +1,6 @@
1
+ import type { FormForgeDraftResponse, FormForgeDraftSaveInput, FormForgeHttpAdapter } from '../types/index.js';
2
+ import { type FormForgeRequestOptions } from './request.js';
3
+ export declare function saveFormForgeDraft(http: FormForgeHttpAdapter, key: string, input: FormForgeDraftSaveInput, options?: FormForgeRequestOptions): Promise<FormForgeDraftResponse>;
4
+ export declare function fetchCurrentFormForgeDraft(http: FormForgeHttpAdapter, key: string, options?: FormForgeRequestOptions): Promise<FormForgeDraftResponse>;
5
+ export declare function deleteCurrentFormForgeDraft(http: FormForgeHttpAdapter, key: string, options?: FormForgeRequestOptions): Promise<FormForgeDraftResponse>;
6
+ //# sourceMappingURL=drafts.d.ts.map
@@ -0,0 +1,77 @@
1
+ import { isFormForgeJsonObject } from "../utils/object.js";
2
+ import { resolveEndpointPath } from "./request.js";
3
+ function pickNullableDataEnvelope(payload) {
4
+ const dataValue = payload.data;
5
+ if (dataValue === null) {
6
+ return null;
7
+ }
8
+ if (isFormForgeJsonObject(dataValue)) {
9
+ return dataValue;
10
+ }
11
+ return payload;
12
+ }
13
+ function toDraftRecord(value) {
14
+ if (value === null) {
15
+ return null;
16
+ }
17
+ const payloadValue = value.payload;
18
+ const payload = isFormForgeJsonObject(payloadValue) ? payloadValue : {};
19
+ const metaValue = value.meta;
20
+ const meta = isFormForgeJsonObject(metaValue) ? metaValue : void 0;
21
+ const ownerIdValue = value.owner_id;
22
+ const ownerId = typeof ownerIdValue === "string" || typeof ownerIdValue === "number" || ownerIdValue === null ? ownerIdValue : void 0;
23
+ return {
24
+ form_key: typeof value.form_key === "string" ? value.form_key : "",
25
+ form_version: typeof value.form_version === "string" ? value.form_version : void 0,
26
+ owner_type: typeof value.owner_type === "string" ? value.owner_type : void 0,
27
+ owner_id: ownerId,
28
+ payload,
29
+ meta,
30
+ expires_at: typeof value.expires_at === "string" || value.expires_at === null ? value.expires_at : void 0,
31
+ created_at: typeof value.created_at === "string" ? value.created_at : void 0,
32
+ updated_at: typeof value.updated_at === "string" ? value.updated_at : void 0
33
+ };
34
+ }
35
+ export async function saveFormForgeDraft(http, key, input, options = {}) {
36
+ const body = {
37
+ payload: JSON.parse(JSON.stringify(input.payload))
38
+ };
39
+ if (input.meta !== void 0) {
40
+ body.meta = input.meta;
41
+ }
42
+ const response = await http({
43
+ path: resolveEndpointPath(options.endpoint, `/forms/${key}/drafts`, {
44
+ key
45
+ }, options.scope),
46
+ method: "POST",
47
+ json: body
48
+ });
49
+ return {
50
+ data: toDraftRecord(pickNullableDataEnvelope(response.data)),
51
+ meta: isFormForgeJsonObject(response.data.meta) ? response.data.meta : void 0
52
+ };
53
+ }
54
+ export async function fetchCurrentFormForgeDraft(http, key, options = {}) {
55
+ const response = await http({
56
+ path: resolveEndpointPath(options.endpoint, `/forms/${key}/drafts/current`, {
57
+ key
58
+ }, options.scope),
59
+ method: "GET"
60
+ });
61
+ return {
62
+ data: toDraftRecord(pickNullableDataEnvelope(response.data)),
63
+ meta: isFormForgeJsonObject(response.data.meta) ? response.data.meta : void 0
64
+ };
65
+ }
66
+ export async function deleteCurrentFormForgeDraft(http, key, options = {}) {
67
+ const response = await http({
68
+ path: resolveEndpointPath(options.endpoint, `/forms/${key}/drafts/current`, {
69
+ key
70
+ }, options.scope),
71
+ method: "DELETE"
72
+ });
73
+ return {
74
+ data: toDraftRecord(pickNullableDataEnvelope(response.data)),
75
+ meta: isFormForgeJsonObject(response.data.meta) ? response.data.meta : void 0
76
+ };
77
+ }
@@ -0,0 +1,3 @@
1
+ import type { FormForgeClientConfig, FormForgeHttpAdapter } from '../types/index.js';
2
+ export declare function createFormForgeHttpAdapter(config?: FormForgeClientConfig): FormForgeHttpAdapter;
3
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1,138 @@
1
+ import { normalizeFormForgeClientError, normalizeNetworkFormForgeError } from "../validation/errors.js";
2
+ import { isFormForgeJsonObject } from "../utils/object.js";
3
+ function normalizeBaseUrl(baseURL) {
4
+ if (baseURL === void 0 || baseURL === "") {
5
+ return "/api/formforge/v1";
6
+ }
7
+ if (baseURL.endsWith("/")) {
8
+ return baseURL.slice(0, -1);
9
+ }
10
+ return baseURL;
11
+ }
12
+ function resolveBaseURLParams(input) {
13
+ if (input === void 0) {
14
+ return {};
15
+ }
16
+ if (typeof input === "function") {
17
+ return input();
18
+ }
19
+ return input;
20
+ }
21
+ function resolveBaseURL(baseURLTemplate, paramsInput) {
22
+ if (!baseURLTemplate.includes("{")) {
23
+ return baseURLTemplate;
24
+ }
25
+ const params = resolveBaseURLParams(paramsInput);
26
+ return baseURLTemplate.replaceAll(/\{([a-zA-Z0-9_]+)\}/g, (token, key) => {
27
+ const value = params[key];
28
+ if (value === void 0 || value === "") {
29
+ return token;
30
+ }
31
+ return encodeURIComponent(String(value));
32
+ });
33
+ }
34
+ function normalizePath(path) {
35
+ if (path.startsWith("/")) {
36
+ return path;
37
+ }
38
+ return `/${path}`;
39
+ }
40
+ function appendQuery(path, query) {
41
+ if (query === void 0) {
42
+ return path;
43
+ }
44
+ const queryParams = new URLSearchParams();
45
+ for (const [key, value] of Object.entries(query)) {
46
+ if (value === void 0) {
47
+ continue;
48
+ }
49
+ queryParams.set(key, String(value));
50
+ }
51
+ const rawQuery = queryParams.toString();
52
+ if (rawQuery.length === 0) {
53
+ return path;
54
+ }
55
+ return `${path}?${rawQuery}`;
56
+ }
57
+ function toJsonPayload(text) {
58
+ if (text.length === 0) {
59
+ return null;
60
+ }
61
+ try {
62
+ return JSON.parse(text);
63
+ } catch {
64
+ return null;
65
+ }
66
+ }
67
+ async function parseResponsePayload(response) {
68
+ if (response.status === 204) {
69
+ return null;
70
+ }
71
+ const text = await response.text();
72
+ const jsonPayload = toJsonPayload(text);
73
+ if (isFormForgeJsonObject(jsonPayload)) {
74
+ return jsonPayload;
75
+ }
76
+ if (text.length > 0) {
77
+ return {
78
+ message: text
79
+ };
80
+ }
81
+ return null;
82
+ }
83
+ async function runBeforeRequest(callback, request, headers, url) {
84
+ if (callback === void 0) {
85
+ return;
86
+ }
87
+ const context = {
88
+ request,
89
+ headers,
90
+ url
91
+ };
92
+ await callback(context);
93
+ }
94
+ export function createFormForgeHttpAdapter(config = {}) {
95
+ const baseURLTemplate = normalizeBaseUrl(config.baseURL);
96
+ const fetchImpl = config.fetch ?? fetch;
97
+ const defaultHeaders = {
98
+ Accept: "application/json",
99
+ ...config.headers ?? {}
100
+ };
101
+ const credentials = config.credentials ?? "include";
102
+ return async function formForgeHttpAdapter(request) {
103
+ const endpointPath = normalizePath(request.path);
104
+ const resolvedBaseURL = resolveBaseURL(baseURLTemplate, config.baseURLParams);
105
+ const targetPath = appendQuery(`${resolvedBaseURL}${endpointPath}`, request.query);
106
+ const headers = {
107
+ ...defaultHeaders,
108
+ ...request.headers ?? {}
109
+ };
110
+ let body = request.body;
111
+ if (request.json !== void 0) {
112
+ headers["Content-Type"] = "application/json";
113
+ body = JSON.stringify(request.json);
114
+ }
115
+ await runBeforeRequest(config.beforeRequest, request, headers, targetPath);
116
+ let response;
117
+ try {
118
+ response = await fetchImpl(targetPath, {
119
+ method: request.method,
120
+ headers,
121
+ credentials,
122
+ body
123
+ });
124
+ } catch {
125
+ throw normalizeNetworkFormForgeError("Network request failed");
126
+ }
127
+ const payload = await parseResponsePayload(response);
128
+ if (!response.ok) {
129
+ throw normalizeFormForgeClientError(response.status, payload);
130
+ }
131
+ const data = payload ?? {};
132
+ return {
133
+ status: response.status,
134
+ headers: response.headers,
135
+ data
136
+ };
137
+ };
138
+ }
@@ -0,0 +1,9 @@
1
+ export { createFormForgeClient } from './client.js';
2
+ export { resolveFormForgeSchema, fetchFormForgeSchema, fetchFormForgeSchemaVersion, fetchFormForgeSchemaVersions } from './schema.js';
3
+ export { saveFormForgeDraft, fetchCurrentFormForgeDraft, deleteCurrentFormForgeDraft } from './drafts.js';
4
+ export { fetchFormForgeResponses, fetchFormForgeResponse, deleteFormForgeResponse } from './responses.js';
5
+ export { fetchFormForgeCategories, fetchFormForgeCategory, createFormForgeCategory, patchFormForgeCategory, deleteFormForgeCategory } from './categories.js';
6
+ export type { FormForgeClient, FormForgeSubmitRequestOptions, FormForgeSubmitMultipartOptions } from './client.js';
7
+ export type { FormForgeMutationOptions, FormForgeManagementRequestOptions } from './management.js';
8
+ export type { FormForgeRequestOptions } from './request.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ export { createFormForgeClient } from "./client.js";
2
+ export { resolveFormForgeSchema, fetchFormForgeSchema, fetchFormForgeSchemaVersion, fetchFormForgeSchemaVersions } from "./schema.js";
3
+ export { saveFormForgeDraft, fetchCurrentFormForgeDraft, deleteCurrentFormForgeDraft } from "./drafts.js";
4
+ export { fetchFormForgeResponses, fetchFormForgeResponse, deleteFormForgeResponse } from "./responses.js";
5
+ export {
6
+ fetchFormForgeCategories,
7
+ fetchFormForgeCategory,
8
+ createFormForgeCategory,
9
+ patchFormForgeCategory,
10
+ deleteFormForgeCategory
11
+ } from "./categories.js";
@@ -0,0 +1,19 @@
1
+ import type { FormForgeDiffResponse, FormForgeHttpAdapter, FormForgeManagementCreateInput, FormForgeManagementForm, FormForgeManagementPatchInput, FormForgeRevisionSummary } from '../types/index.js';
2
+ import { type FormForgeRequestOptions } from './request.js';
3
+ export interface FormForgeMutationOptions extends FormForgeRequestOptions {
4
+ idempotencyKey?: string;
5
+ }
6
+ export type FormForgeManagementFilterValue = string | number | boolean | undefined;
7
+ export type FormForgeManagementFilters = Record<string, FormForgeManagementFilterValue>;
8
+ export interface FormForgeManagementRequestOptions extends FormForgeRequestOptions {
9
+ filters?: FormForgeManagementFilters;
10
+ }
11
+ export declare function createFormForgeForm(http: FormForgeHttpAdapter, input: FormForgeManagementCreateInput, options?: FormForgeMutationOptions): Promise<FormForgeManagementForm>;
12
+ export declare function fetchFormForgeForms(http: FormForgeHttpAdapter, includeDeleted?: boolean, options?: FormForgeManagementRequestOptions): Promise<FormForgeManagementForm[]>;
13
+ export declare function patchFormForgeForm(http: FormForgeHttpAdapter, key: string, input: FormForgeManagementPatchInput, options?: FormForgeMutationOptions): Promise<FormForgeManagementForm>;
14
+ export declare function publishFormForgeForm(http: FormForgeHttpAdapter, key: string, options?: FormForgeMutationOptions): Promise<FormForgeManagementForm>;
15
+ export declare function unpublishFormForgeForm(http: FormForgeHttpAdapter, key: string, options?: FormForgeMutationOptions): Promise<FormForgeManagementForm>;
16
+ export declare function deleteFormForgeForm(http: FormForgeHttpAdapter, key: string, options?: FormForgeMutationOptions): Promise<FormForgeManagementForm>;
17
+ export declare function fetchFormForgeRevisions(http: FormForgeHttpAdapter, key: string, includeDeleted?: boolean, options?: FormForgeManagementRequestOptions): Promise<FormForgeRevisionSummary[]>;
18
+ export declare function fetchFormForgeDiff(http: FormForgeHttpAdapter, key: string, fromVersion: number, toVersion: number, options?: FormForgeManagementRequestOptions): Promise<FormForgeDiffResponse>;
19
+ //# sourceMappingURL=management.d.ts.map
@@ -0,0 +1,180 @@
1
+ import { isFormForgeJsonObject, pickFormForgeDataEnvelope } from "../utils/object.js";
2
+ import { normalizeFormForgeCategory } from "../utils/category.js";
3
+ import { resolveEndpointPath } from "./request.js";
4
+ function normalizeManagementForm(value) {
5
+ if (!isFormForgeJsonObject(value)) {
6
+ return null;
7
+ }
8
+ const rawValue = value;
9
+ const category = typeof rawValue.category === "string" || rawValue.category === null ? rawValue.category : void 0;
10
+ const rawCategoryItem = rawValue.category_item;
11
+ const categoryItem = rawCategoryItem === null ? null : normalizeFormForgeCategory(rawCategoryItem);
12
+ const normalized = {
13
+ ...rawValue
14
+ };
15
+ if (category !== void 0) {
16
+ normalized.category = category;
17
+ }
18
+ if (rawCategoryItem === null || categoryItem !== null) {
19
+ normalized.category_item = categoryItem;
20
+ }
21
+ return normalized;
22
+ }
23
+ function asManagementFormArray(value) {
24
+ if (!Array.isArray(value)) {
25
+ return [];
26
+ }
27
+ const items = [];
28
+ for (const item of value) {
29
+ const normalized = normalizeManagementForm(item);
30
+ if (normalized !== null) {
31
+ items.push(normalized);
32
+ }
33
+ }
34
+ return items;
35
+ }
36
+ function normalizeFormsList(payload) {
37
+ const dataValue = payload.data;
38
+ if (Array.isArray(dataValue)) {
39
+ return asManagementFormArray(dataValue);
40
+ }
41
+ if (!isFormForgeJsonObject(dataValue)) {
42
+ return asManagementFormArray(payload.items ?? payload.forms);
43
+ }
44
+ const nestedData = dataValue.data;
45
+ if (Array.isArray(nestedData)) {
46
+ return asManagementFormArray(nestedData);
47
+ }
48
+ return asManagementFormArray(dataValue.items ?? dataValue.forms);
49
+ }
50
+ function withMutationHeaders(options = {}) {
51
+ if (options.idempotencyKey === void 0 || options.idempotencyKey === "") {
52
+ return {};
53
+ }
54
+ return {
55
+ "Idempotency-Key": options.idempotencyKey
56
+ };
57
+ }
58
+ function toJsonObject(input) {
59
+ return JSON.parse(JSON.stringify(input));
60
+ }
61
+ export async function createFormForgeForm(http, input, options = {}) {
62
+ const response = await http({
63
+ path: resolveEndpointPath(options.endpoint, "/forms", {}, options.scope),
64
+ method: "POST",
65
+ headers: withMutationHeaders(options),
66
+ json: toJsonObject(input)
67
+ });
68
+ return normalizeManagementForm(pickFormForgeDataEnvelope(response.data)) ?? {};
69
+ }
70
+ export async function fetchFormForgeForms(http, includeDeleted = false, options = {}) {
71
+ const filters = options.filters ?? {};
72
+ const response = await http({
73
+ path: resolveEndpointPath(options.endpoint, "/forms", {}, options.scope),
74
+ method: "GET",
75
+ query: {
76
+ ...filters,
77
+ include_deleted: includeDeleted ? 1 : 0
78
+ }
79
+ });
80
+ return normalizeFormsList(response.data);
81
+ }
82
+ export async function patchFormForgeForm(http, key, input, options = {}) {
83
+ const response = await http({
84
+ path: resolveEndpointPath(options.endpoint, `/forms/${key}`, {
85
+ key
86
+ }, options.scope),
87
+ method: "PATCH",
88
+ headers: withMutationHeaders(options),
89
+ json: toJsonObject(input)
90
+ });
91
+ return normalizeManagementForm(pickFormForgeDataEnvelope(response.data)) ?? {};
92
+ }
93
+ export async function publishFormForgeForm(http, key, options = {}) {
94
+ const response = await http({
95
+ path: resolveEndpointPath(options.endpoint, `/forms/${key}/publish`, {
96
+ key
97
+ }, options.scope),
98
+ method: "POST",
99
+ headers: withMutationHeaders(options)
100
+ });
101
+ return normalizeManagementForm(pickFormForgeDataEnvelope(response.data)) ?? {};
102
+ }
103
+ export async function unpublishFormForgeForm(http, key, options = {}) {
104
+ const response = await http({
105
+ path: resolveEndpointPath(options.endpoint, `/forms/${key}/unpublish`, {
106
+ key
107
+ }, options.scope),
108
+ method: "POST",
109
+ headers: withMutationHeaders(options)
110
+ });
111
+ return normalizeManagementForm(pickFormForgeDataEnvelope(response.data)) ?? {};
112
+ }
113
+ export async function deleteFormForgeForm(http, key, options = {}) {
114
+ const response = await http({
115
+ path: resolveEndpointPath(options.endpoint, `/forms/${key}`, {
116
+ key
117
+ }, options.scope),
118
+ method: "DELETE",
119
+ headers: withMutationHeaders(options)
120
+ });
121
+ return normalizeManagementForm(pickFormForgeDataEnvelope(response.data)) ?? {};
122
+ }
123
+ export async function fetchFormForgeRevisions(http, key, includeDeleted = false, options = {}) {
124
+ const response = await http({
125
+ path: resolveEndpointPath(options.endpoint, `/forms/${key}/revisions`, {
126
+ key
127
+ }, options.scope),
128
+ method: "GET",
129
+ query: {
130
+ include_deleted: includeDeleted ? 1 : 0
131
+ }
132
+ });
133
+ const dataEnvelope = pickFormForgeDataEnvelope(response.data);
134
+ const revisionsValue = dataEnvelope.revisions ?? dataEnvelope.data ?? dataEnvelope.items;
135
+ if (!Array.isArray(revisionsValue)) {
136
+ return [];
137
+ }
138
+ const revisions = [];
139
+ for (const item of revisionsValue) {
140
+ if (!isFormForgeJsonObject(item)) {
141
+ continue;
142
+ }
143
+ const revisionId = typeof item.revision_id === "string" ? item.revision_id : "";
144
+ const versionNumber = typeof item.version_number === "number" ? item.version_number : 0;
145
+ const isPublished = typeof item.is_published === "boolean" ? item.is_published : false;
146
+ revisions.push({
147
+ revision_id: revisionId,
148
+ version_number: versionNumber,
149
+ is_published: isPublished,
150
+ created_at: typeof item.created_at === "string" ? item.created_at : void 0,
151
+ deleted_at: typeof item.deleted_at === "string" || item.deleted_at === null ? item.deleted_at : void 0
152
+ });
153
+ }
154
+ return revisions;
155
+ }
156
+ export async function fetchFormForgeDiff(http, key, fromVersion, toVersion, options = {}) {
157
+ const response = await http({
158
+ path: resolveEndpointPath(options.endpoint, `/forms/${key}/diff/${fromVersion}/${toVersion}`, {
159
+ key,
160
+ fromVersion,
161
+ toVersion
162
+ }, options.scope),
163
+ method: "GET"
164
+ });
165
+ const dataEnvelope = pickFormForgeDataEnvelope(response.data);
166
+ const changesValue = dataEnvelope.changes;
167
+ const changes = [];
168
+ if (Array.isArray(changesValue)) {
169
+ for (const item of changesValue) {
170
+ if (isFormForgeJsonObject(item)) {
171
+ changes.push(item);
172
+ }
173
+ }
174
+ }
175
+ return {
176
+ from_version: typeof dataEnvelope.from_version === "number" ? dataEnvelope.from_version : fromVersion,
177
+ to_version: typeof dataEnvelope.to_version === "number" ? dataEnvelope.to_version : toVersion,
178
+ changes
179
+ };
180
+ }
@@ -0,0 +1,8 @@
1
+ import type { FormForgeScope } from '../types/index.js';
2
+ export interface FormForgeRequestOptions {
3
+ endpoint?: string;
4
+ scope?: FormForgeScope;
5
+ }
6
+ export declare function applyFormForgeScope(path: string, scope: FormForgeScope | undefined): string;
7
+ export declare function resolveEndpointPath(endpoint: string | undefined, fallback: string, params?: Record<string, string | number>, scope?: FormForgeScope | undefined): string;
8
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1,52 @@
1
+ const TEMPLATE_PARAM_PATTERN = /\{([a-zA-Z0-9_]+)(?::[^}]+)?\}/g;
2
+ function normalizePath(path) {
3
+ if (path.startsWith("/")) {
4
+ return path;
5
+ }
6
+ return `/${path}`;
7
+ }
8
+ function stripWrappingSlashes(value) {
9
+ return value.replaceAll(/^\/+|\/+$/g, "");
10
+ }
11
+ function replaceTemplateParams(template, params, strict, context) {
12
+ return template.replaceAll(TEMPLATE_PARAM_PATTERN, (token, key) => {
13
+ const value = params[key];
14
+ if (value === void 0 || value === "") {
15
+ if (strict) {
16
+ throw new Error(`Missing required scope param "${key}" for scope prefix "${context ?? template}"`);
17
+ }
18
+ return token;
19
+ }
20
+ return encodeURIComponent(String(value));
21
+ });
22
+ }
23
+ function resolveScopeInput(scope) {
24
+ if (scope === void 0) {
25
+ return void 0;
26
+ }
27
+ if (typeof scope === "string") {
28
+ throw new Error(`Named scope "${scope}" is not resolved. Use createFormForgeClient with scopedRoutes/defaultScope or pass a scope object.`);
29
+ }
30
+ return scope;
31
+ }
32
+ export function applyFormForgeScope(path, scope) {
33
+ const resolvedScope = resolveScopeInput(scope);
34
+ const normalizedPath = normalizePath(path);
35
+ if (resolvedScope === void 0) {
36
+ return normalizedPath;
37
+ }
38
+ const trimmedPrefix = stripWrappingSlashes(resolvedScope.prefix);
39
+ if (trimmedPrefix === "") {
40
+ return normalizedPath;
41
+ }
42
+ const resolvedPrefix = replaceTemplateParams(trimmedPrefix, resolvedScope.params, true, resolvedScope.prefix);
43
+ if (normalizedPath === "/") {
44
+ return `/${resolvedPrefix}`;
45
+ }
46
+ return `/${resolvedPrefix}${normalizedPath}`;
47
+ }
48
+ export function resolveEndpointPath(endpoint, fallback, params = {}, scope = void 0) {
49
+ const template = typeof endpoint === "string" && endpoint !== "" ? endpoint : fallback;
50
+ const resolvedPath = replaceTemplateParams(template, params, false);
51
+ return applyFormForgeScope(resolvedPath, scope);
52
+ }
@@ -0,0 +1,6 @@
1
+ import type { FormForgeHttpAdapter, FormForgeJsonObject, FormForgeResponsesListResponse } from '../types/index.js';
2
+ import { type FormForgeRequestOptions } from './request.js';
3
+ export declare function fetchFormForgeResponses(http: FormForgeHttpAdapter, key: string, query?: Record<string, string | number | boolean | undefined>, options?: FormForgeRequestOptions): Promise<FormForgeResponsesListResponse>;
4
+ export declare function fetchFormForgeResponse(http: FormForgeHttpAdapter, key: string, submissionId: string, options?: FormForgeRequestOptions): Promise<FormForgeJsonObject>;
5
+ export declare function deleteFormForgeResponse(http: FormForgeHttpAdapter, key: string, submissionId: string, options?: FormForgeRequestOptions): Promise<FormForgeJsonObject>;
6
+ //# sourceMappingURL=responses.d.ts.map