dalux-build-api 1.1.5 → 2.0.1

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 (39) hide show
  1. package/README.md +257 -187
  2. package/package.json +11 -4
  3. package/src/api/CompaniesApi.js +19 -12
  4. package/src/api/CompanyCatalogApi.js +22 -18
  5. package/src/api/FileAreasApi.js +14 -12
  6. package/src/api/FilesApi.js +11 -7
  7. package/src/api/FoldersApi.js +14 -12
  8. package/src/api/FormsApi.js +11 -6
  9. package/src/api/InspectionPlansApi.js +87 -9
  10. package/src/api/ProjectsApi.js +22 -18
  11. package/src/api/TasksApi.js +25 -10
  12. package/src/api/TestPlansApi.js +87 -9
  13. package/src/api/UsersApi.js +11 -6
  14. package/src/api/VersionSetsApi.js +20 -12
  15. package/src/api/WorkPackagesApi.js +7 -3
  16. package/src/browser.js +84 -0
  17. package/src/index.js +5 -0
  18. package/src/models/common.js +22 -0
  19. package/src/models/companies/index.js +14 -0
  20. package/src/models/companyCatalog/index.js +19 -0
  21. package/src/models/convert.js +44 -0
  22. package/src/models/fileAreas/index.js +20 -0
  23. package/src/models/fileRevisions/index.js +12 -0
  24. package/src/models/fileUpload/index.js +12 -0
  25. package/src/models/files/index.js +97 -0
  26. package/src/models/folders/index.js +20 -0
  27. package/src/models/forms/index.js +19 -0
  28. package/src/models/helpers.js +62 -0
  29. package/src/models/index.js +178 -0
  30. package/src/models/inspectionPlans/index.js +61 -0
  31. package/src/models/projectTemplates/index.js +11 -0
  32. package/src/models/projects/index.js +57 -0
  33. package/src/models/tasks/index.js +105 -0
  34. package/src/models/testPlans/index.js +61 -0
  35. package/src/models/users/index.js +29 -0
  36. package/src/models/versionSets/index.js +22 -0
  37. package/src/models/workPackages/index.js +19 -0
  38. package/src/next.js +89 -0
  39. package/LICENSE +0 -21
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const { z } = require('zod');
4
+ const { listResponseSchema, singleResponseSchema } = require('../helpers');
5
+
6
+ /** Mirrors models/users/models.py::User. */
7
+ const UserSchema = z.object({
8
+ userId: z.string(),
9
+ userType: z.string(),
10
+ email: z.string().email(),
11
+ firstName: z.string().nullish(),
12
+ lastName: z.string().nullish(),
13
+ });
14
+
15
+ /** Mirrors models/users/models.py::ProjectUser (User + companyId). */
16
+ const ProjectUserSchema = UserSchema.extend({
17
+ companyId: z.string().nullish(),
18
+ });
19
+
20
+ const UsersListResponseSchema = listResponseSchema(ProjectUserSchema);
21
+ /** Single-user response wraps User, not ProjectUser — matches Python. */
22
+ const UserResponseSchema = singleResponseSchema(UserSchema);
23
+
24
+ module.exports = {
25
+ UserSchema,
26
+ ProjectUserSchema,
27
+ UsersListResponseSchema,
28
+ UserResponseSchema,
29
+ };
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const { z } = require('zod');
4
+ const { listResponseSchema, singleResponseSchema } = require('../helpers');
5
+
6
+ /** Mirrors models/version_sets/models.py::VersionSet. */
7
+ const VersionSetSchema = z.object({
8
+ versionSetId: z.string(),
9
+ name: z.string(),
10
+ description: z.string().nullish(),
11
+ status: z.string().nullish(),
12
+ fileAreaId: z.string(),
13
+ });
14
+
15
+ const VersionSetsListResponseSchema = listResponseSchema(VersionSetSchema);
16
+ const VersionSetResponseSchema = singleResponseSchema(VersionSetSchema);
17
+
18
+ module.exports = {
19
+ VersionSetSchema,
20
+ VersionSetsListResponseSchema,
21
+ VersionSetResponseSchema,
22
+ };
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ const { z } = require('zod');
4
+ const { listResponseSchema } = require('../helpers');
5
+
6
+ /** Mirrors models/work_packages/models.py::WorkPackage (extra="allow" -> passthrough). */
7
+ const WorkPackageSchema = z.object({
8
+ workpackageId: z.string().nullish(),
9
+ companyId: z.string().nullish(),
10
+ name: z.string().nullish(),
11
+ }).passthrough();
12
+
13
+ /** No single-item response class in Python. */
14
+ const WorkPackagesListResponseSchema = listResponseSchema(WorkPackageSchema);
15
+
16
+ module.exports = {
17
+ WorkPackageSchema,
18
+ WorkPackagesListResponseSchema,
19
+ };
package/src/next.js ADDED
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ function normalizeAllowedMethods(allowedMethods) {
4
+ const normalized = new Set();
5
+ if (Array.isArray(allowedMethods)) {
6
+ for (const method of allowedMethods) normalized.add(method);
7
+ } else if (allowedMethods && typeof allowedMethods === 'object') {
8
+ for (const [resource, methods] of Object.entries(allowedMethods)) {
9
+ for (const method of methods) normalized.add(`${resource}.${method}`);
10
+ }
11
+ }
12
+ if (normalized.size === 0) {
13
+ throw new Error('allowedMethods must explicitly expose at least one Dalux client method');
14
+ }
15
+ return normalized;
16
+ }
17
+
18
+ function json(body, status = 200) {
19
+ return Response.json(body, { status });
20
+ }
21
+
22
+ function errorStatus(error) {
23
+ if (error?.name === 'AuthenticationError') return 401;
24
+ if (error?.name === 'NotFoundError') return 404;
25
+ if (error?.name === 'RateLimitError') return 429;
26
+ if (error?.name === 'ValidationError') return 422;
27
+ return 502;
28
+ }
29
+
30
+ /**
31
+ * Create a Next.js App Router POST handler for a browser Dalux client.
32
+ *
33
+ * @param {object} options
34
+ * @param {object} options.client A server-side client from createClient().
35
+ * @param {string[]|Record<string, string[]>} options.allowedMethods Explicit RPC allow-list.
36
+ * @param {(request: Request) => boolean|Response|Promise<boolean|Response>} [options.authorize]
37
+ * @returns {(request: Request) => Promise<Response>}
38
+ */
39
+ function createDaluxRouteHandler({ client, allowedMethods, authorize } = {}) {
40
+ if (!client || typeof client !== 'object') {
41
+ throw new Error('A server-side Dalux client is required');
42
+ }
43
+ const allowed = normalizeAllowedMethods(allowedMethods);
44
+
45
+ return async function POST(request) {
46
+ if (authorize) {
47
+ const authorization = await authorize(request);
48
+ if (authorization instanceof Response) return authorization;
49
+ if (!authorization) return json({ ok: false, error: { name: 'AuthenticationError', message: 'Unauthorized' } }, 401);
50
+ }
51
+
52
+ let payload;
53
+ try {
54
+ payload = await request.json();
55
+ } catch {
56
+ return json({ ok: false, error: { name: 'ValidationError', message: 'Request body must be JSON' } }, 400);
57
+ }
58
+
59
+ const { resource, method, args = [] } = payload || {};
60
+ const qualifiedMethod = `${resource}.${method}`;
61
+ if (!allowed.has(qualifiedMethod)) {
62
+ return json({ ok: false, error: { name: 'NotFoundError', message: `Method ${qualifiedMethod} is not exposed` } }, 404);
63
+ }
64
+ if (!Array.isArray(args)) {
65
+ return json({ ok: false, error: { name: 'ValidationError', message: 'args must be an array' } }, 400);
66
+ }
67
+
68
+ const target = client[resource];
69
+ const operation = target?.[method];
70
+ if (typeof operation !== 'function') {
71
+ return json({ ok: false, error: { name: 'NotFoundError', message: `Unknown method ${qualifiedMethod}` } }, 404);
72
+ }
73
+
74
+ try {
75
+ const data = await operation.apply(target, args);
76
+ return json({ ok: true, data: data === undefined ? null : data });
77
+ } catch (error) {
78
+ return json({
79
+ ok: false,
80
+ error: {
81
+ name: error?.name || 'ApiError',
82
+ message: error?.message || String(error),
83
+ },
84
+ }, errorStatus(error));
85
+ }
86
+ };
87
+ }
88
+
89
+ module.exports = { createDaluxRouteHandler };
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Bruno Adam
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.