swoop-common 2.1.49 → 2.1.51

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 (41) hide show
  1. package/dist/api/additions/templateHierarchyResolver.js +52 -49
  2. package/dist/api/bundler.js +57 -24
  3. package/dist/api/generated/core/core/OpenAPI.js +2 -2
  4. package/dist/api/generated/core/exports.d.ts +2 -0
  5. package/dist/api/generated/core/index.d.ts +4 -0
  6. package/dist/api/generated/core/index.js +2 -0
  7. package/dist/api/generated/core/models/DTOSnapshotCreate.d.ts +0 -1
  8. package/dist/api/generated/core/models/DTOSnapshotEntity.d.ts +0 -1
  9. package/dist/api/generated/core/models/DTOSnapshotRead.d.ts +0 -1
  10. package/dist/api/generated/core/models/Error.d.ts +1 -0
  11. package/dist/api/generated/core/models/Error.js +1 -0
  12. package/dist/api/generated/core/models/itineraryIdQuery.d.ts +4 -0
  13. package/dist/api/generated/core/models/itineraryIdQuery.js +1 -0
  14. package/dist/api/generated/core/services/ComponentService.d.ts +73 -0
  15. package/dist/api/generated/core/services/ComponentService.js +171 -0
  16. package/dist/api/generated/core/services/CoreService.d.ts +48 -36
  17. package/dist/api/generated/core/services/CoreService.js +131 -32
  18. package/dist/api/generated/core/services/TemplateService.d.ts +53 -0
  19. package/dist/api/generated/core/services/TemplateService.js +121 -0
  20. package/dist/api/generated/itinerary/core/OpenAPI.js +2 -2
  21. package/dist/api/generated/itinerary/index.d.ts +5 -0
  22. package/dist/api/generated/itinerary/index.js +3 -0
  23. package/dist/api/generated/itinerary/models/DTOSnapshotCreate.d.ts +0 -1
  24. package/dist/api/generated/itinerary/models/DTOSnapshotEntity.d.ts +0 -1
  25. package/dist/api/generated/itinerary/models/DTOSnapshotRead.d.ts +0 -1
  26. package/dist/api/generated/itinerary/models/Error.d.ts +1 -0
  27. package/dist/api/generated/itinerary/models/Error.js +1 -0
  28. package/dist/api/generated/itinerary/models/itineraryIdQuery.d.ts +4 -0
  29. package/dist/api/generated/itinerary/models/itineraryIdQuery.js +1 -0
  30. package/dist/api/generated/itinerary/services/AuditService.d.ts +12 -0
  31. package/dist/api/generated/itinerary/services/AuditService.js +28 -0
  32. package/dist/api/generated/itinerary/services/ItineraryService.d.ts +38 -34
  33. package/dist/api/generated/itinerary/services/ItineraryService.js +123 -22
  34. package/dist/api/generated/itinerary/services/RegionService.d.ts +27 -0
  35. package/dist/api/generated/itinerary/services/RegionService.js +51 -0
  36. package/dist/api/generated/itinerary/services/SnapshotService.d.ts +51 -0
  37. package/dist/api/generated/itinerary/services/SnapshotService.js +117 -0
  38. package/dist/rendering/components/ComponentPicker.d.ts +1 -1
  39. package/dist/rendering/components/ComponentPicker.js +33 -20
  40. package/dist/rendering/renderers/TemplatePicker.js +15 -15
  41. package/package.json +4 -1
@@ -43,59 +43,62 @@ const buildTemplateTree = (templates) => {
43
43
  };
44
44
  export const resolveTemplateHierarchy = (templateId) => __awaiter(void 0, void 0, void 0, function* () {
45
45
  // First fetch all templates
46
- const allTemplates = yield (new CoreService).templateList(1);
47
- // Find the initial template
48
- const initialTemplate = allTemplates.data.find((t) => t.id === templateId);
49
- if (!initialTemplate) {
50
- throw new Error(`Template with ID ${templateId} not found`);
51
- }
52
- // Build the complete template tree
53
- const templateTree = buildTemplateTree(allTemplates.data);
54
- // Find the group containing our template
55
- const findGroup = (groups) => {
56
- for (const group of groups) {
57
- if (group.versions.some((t) => t.id === templateId)) {
58
- return group;
46
+ const allTemplates = yield new CoreService().templateList(1);
47
+ if (allTemplates.data) {
48
+ // Find the initial template
49
+ const initialTemplate = allTemplates.data.find((t) => t.id === templateId);
50
+ if (!initialTemplate) {
51
+ throw new Error(`Template with ID ${templateId} not found`);
52
+ }
53
+ // Build the complete template tree
54
+ const templateTree = buildTemplateTree(allTemplates.data);
55
+ // Find the group containing our template
56
+ const findGroup = (groups) => {
57
+ for (const group of groups) {
58
+ if (group.versions.some((t) => t.id === templateId)) {
59
+ return group;
60
+ }
61
+ const found = findGroup(group.children);
62
+ if (found)
63
+ return found;
59
64
  }
60
- const found = findGroup(group.children);
61
- if (found)
62
- return found;
65
+ return undefined;
66
+ };
67
+ const targetGroup = findGroup(templateTree);
68
+ if (!targetGroup) {
69
+ throw new Error(`Could not find template group for template ${templateId}`);
63
70
  }
64
- return undefined;
65
- };
66
- const targetGroup = findGroup(templateTree);
67
- if (!targetGroup) {
68
- throw new Error(`Could not find template group for template ${templateId}`);
69
- }
70
- // Build the hierarchy by following parent links
71
- const hierarchy = [];
72
- let currentGroup = targetGroup;
73
- while (currentGroup) {
74
- // Get the latest version of the current group
75
- const latestTemplate = currentGroup.versions.reduce((a, b) => a.revision > b.revision ? a : b);
76
- hierarchy.unshift(latestTemplate); // Add to beginning to get root -> leaf order
77
- // Move up to parent group
78
- if (currentGroup.parentRevisionGroupId) {
79
- // Find the parent group in the tree
80
- const findParentGroup = (groups) => {
81
- for (const group of groups) {
82
- if (group.revisionGroupId === currentGroup.parentRevisionGroupId) {
83
- return group;
71
+ // Build the hierarchy by following parent links
72
+ const hierarchy = [];
73
+ let currentGroup = targetGroup;
74
+ while (currentGroup) {
75
+ // Get the latest version of the current group
76
+ const latestTemplate = currentGroup.versions.reduce((a, b) => a.revision > b.revision ? a : b);
77
+ hierarchy.unshift(latestTemplate); // Add to beginning to get root -> leaf order
78
+ // Move up to parent group
79
+ if (currentGroup.parentRevisionGroupId) {
80
+ // Find the parent group in the tree
81
+ const findParentGroup = (groups) => {
82
+ for (const group of groups) {
83
+ if (group.revisionGroupId === currentGroup.parentRevisionGroupId) {
84
+ return group;
85
+ }
86
+ const found = findParentGroup(group.children);
87
+ if (found)
88
+ return found;
84
89
  }
85
- const found = findParentGroup(group.children);
86
- if (found)
87
- return found;
88
- }
89
- return undefined;
90
- };
91
- const parentGroup = findParentGroup(templateTree);
92
- if (!parentGroup)
90
+ return undefined;
91
+ };
92
+ const parentGroup = findParentGroup(templateTree);
93
+ if (!parentGroup)
94
+ break;
95
+ currentGroup = parentGroup;
96
+ }
97
+ else {
93
98
  break;
94
- currentGroup = parentGroup;
95
- }
96
- else {
97
- break;
99
+ }
98
100
  }
101
+ return hierarchy; // Already in root -> leaf order
99
102
  }
100
- return hierarchy; // Already in root -> leaf order
103
+ return [];
101
104
  });
@@ -1,29 +1,62 @@
1
1
  import fs from "fs";
2
- // Super lazy bundler, just sticks models onto the end of specs and updates refs
3
- const bundle = (sdk) => {
4
- const specs = fs.readFileSync(`./openapi/${sdk}_service.yaml`, "utf-8");
5
- const models = fs.readFileSync("./openapi/models.yaml", "utf-8");
6
- // Remove header of models
7
- const clean = models.split("\n");
8
- let reached = false;
9
- let full = "";
10
- for (let i = 0; i < clean.length; i++) {
11
- if (!reached && clean[i].startsWith("components"))
12
- reached = true;
13
- // Removes tags
14
- if (clean[i].startsWith("tags"))
15
- break;
16
- if (reached)
17
- full += "\n" + clean[i];
2
+ import yaml from "js-yaml";
3
+ /**
4
+ * Merge all `components` subsections (schemas, parameters, responses, etc.)
5
+ */
6
+ function mergeComponents(target, source) {
7
+ if (!(source === null || source === void 0 ? void 0 : source.components))
8
+ return;
9
+ if (!target.components) {
10
+ target.components = {};
18
11
  }
19
- // Dont need to parse specs, can just look for references
20
- const updatedSpecs = specs.replace(/\.\/models\.yaml/g, "") + "\n" + full;
21
- // Make sure all refs are wrapped in '
22
- const cleanedSpecs = updatedSpecs.split("\n").map(line => line.replace(/(\$ref:\s*)(["']?)([^"'\s]+)\2/, (_, prefix, _q, path) => {
23
- return `${prefix}'${path}'`;
24
- })).join("\n");
12
+ for (const key of Object.keys(source.components)) {
13
+ if (!target.components[key]) {
14
+ target.components[key] = {};
15
+ }
16
+ Object.assign(target.components[key], source.components[key]);
17
+ }
18
+ }
19
+ /**
20
+ * Fix $ref pointers from external file refs (e.g. ./models.yaml#/...)
21
+ * to internal refs (#/components/...)
22
+ */
23
+ function fixRefs(obj) {
24
+ if (Array.isArray(obj)) {
25
+ return obj.map(fixRefs);
26
+ }
27
+ else if (obj && typeof obj === "object") {
28
+ for (const key of Object.keys(obj)) {
29
+ if (key === "$ref" && typeof obj[key] === "string") {
30
+ obj[key] = obj[key]
31
+ .replace("./models.yaml#", "#")
32
+ .replace("./error.yaml#", "#");
33
+ }
34
+ else {
35
+ obj[key] = fixRefs(obj[key]);
36
+ }
37
+ }
38
+ }
39
+ return obj;
40
+ }
41
+ function bundle(sdk) {
42
+ const servicePath = `./openapi/${sdk}_service.yaml`;
43
+ const modelsPath = "./openapi/models.yaml";
44
+ const errorsPath = "./openapi/error.yaml";
45
+ const outputPath = `./openapi/generated/${sdk}_bundled.yaml`;
46
+ // Load YAML files
47
+ const service = yaml.load(fs.readFileSync(servicePath, "utf-8"));
48
+ const models = yaml.load(fs.readFileSync(modelsPath, "utf-8"));
49
+ const errors = yaml.load(fs.readFileSync(errorsPath, "utf-8"));
50
+ // Merge all components
51
+ mergeComponents(service, models);
52
+ mergeComponents(service, errors);
53
+ // Fix refs
54
+ const fixed = fixRefs(service);
55
+ // Dump back to YAML
56
+ const bundled = yaml.dump(fixed, { noRefs: true, lineWidth: -1 });
25
57
  fs.mkdirSync("./openapi/generated", { recursive: true });
26
- fs.writeFileSync(`./openapi/generated/${sdk}_bundled.yaml`, cleanedSpecs);
27
- };
58
+ fs.writeFileSync(outputPath, bundled);
59
+ console.log(`✅ Bundled ${sdk} -> ${outputPath}`);
60
+ }
28
61
  bundle("core");
29
62
  bundle("itinerary");
@@ -1,6 +1,6 @@
1
1
  export const OpenAPI = {
2
- BASE: 'placeholder',
3
- VERSION: '1.0.0',
2
+ BASE: 'https://data-api-dev.swoop-adventures.com/core-data-service/v1',
3
+ VERSION: '1',
4
4
  WITH_CREDENTIALS: false,
5
5
  CREDENTIALS: 'include',
6
6
  TOKEN: undefined,
@@ -39,12 +39,14 @@ export type { DTOTemplateEntity } from './index';
39
39
  export type { DTOTemplateRead } from './index';
40
40
  export type { DTOTemplateUpdate } from './index';
41
41
  export type { enquiryId } from './index';
42
+ export type { Error } from './index';
42
43
  export type { Fee } from './index';
43
44
  export type { Field } from './index';
44
45
  export type { IBEvent } from './index';
45
46
  export type { id } from './index';
46
47
  export type { itemsPerPage } from './index';
47
48
  export type { itineraryId } from './index';
49
+ export type { itineraryIdQuery } from './index';
48
50
  export type { Limit } from './index';
49
51
  export { Meals } from './index';
50
52
  export type { Member } from './index';
@@ -41,12 +41,14 @@ export type { DTOTemplateEntity } from './models/DTOTemplateEntity';
41
41
  export type { DTOTemplateRead } from './models/DTOTemplateRead';
42
42
  export type { DTOTemplateUpdate } from './models/DTOTemplateUpdate';
43
43
  export type { enquiryId } from './models/enquiryId';
44
+ export type { Error } from './models/Error';
44
45
  export type { Fee } from './models/Fee';
45
46
  export type { Field } from './models/Field';
46
47
  export type { IBEvent } from './models/IBEvent';
47
48
  export type { id } from './models/id';
48
49
  export type { itemsPerPage } from './models/itemsPerPage';
49
50
  export type { itineraryId } from './models/itineraryId';
51
+ export type { itineraryIdQuery } from './models/itineraryIdQuery';
50
52
  export type { Limit } from './models/Limit';
51
53
  export { Meals } from './models/Meals';
52
54
  export type { Member } from './models/Member';
@@ -65,4 +67,6 @@ export type { sortParam } from './models/sortParam';
65
67
  export type { templateId } from './models/templateId';
66
68
  export type { UserComponentInstanceField } from './models/UserComponentInstanceField';
67
69
  export type { ValidationSchemas } from './models/ValidationSchemas';
70
+ export { ComponentService } from './services/ComponentService';
68
71
  export { CoreService } from './services/CoreService';
72
+ export { TemplateService } from './services/TemplateService';
@@ -11,4 +11,6 @@ export { Currency } from './models/Currency';
11
11
  export { Meals } from './models/Meals';
12
12
  export { regionParam } from './models/regionParam';
13
13
  export { regionRequired } from './models/regionRequired';
14
+ export { ComponentService } from './services/ComponentService';
14
15
  export { CoreService } from './services/CoreService';
16
+ export { TemplateService } from './services/TemplateService';
@@ -1,5 +1,4 @@
1
1
  export type DTOSnapshotCreate = {
2
2
  name: string;
3
3
  itineraryId: string;
4
- enquiryId: string;
5
4
  };
@@ -4,5 +4,4 @@ export type DTOSnapshotEntity = {
4
4
  metadata: Metadata;
5
5
  name: string;
6
6
  itineraryId: string;
7
- enquiryId: string;
8
7
  };
@@ -4,5 +4,4 @@ export type DTOSnapshotRead = {
4
4
  metadata: Metadata;
5
5
  name: string;
6
6
  itineraryId: string;
7
- enquiryId: string;
8
7
  };
@@ -0,0 +1 @@
1
+ export type Error = Record<string, any>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Itinerary Id
3
+ */
4
+ export type itineraryIdQuery = string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,73 @@
1
+ import type { DTOComponentCreate } from '../models/DTOComponentCreate';
2
+ import type { DTOComponentRead } from '../models/DTOComponentRead';
3
+ import type { DTOComponentUpdate } from '../models/DTOComponentUpdate';
4
+ import type { Pagination } from '../models/Pagination';
5
+ import type { CancelablePromise } from '../core/CancelablePromise';
6
+ export declare class ComponentService {
7
+ /**
8
+ * List Component
9
+ * List all available component
10
+ * @param page Pagination, starting at page 1
11
+ * @param limit Number of items per page
12
+ * @param sort List of fields to sort by
13
+ * @returns any The list of all component given the parameters used
14
+ * @throws ApiError
15
+ */
16
+ static componentList(page?: number, limit?: number, sort?: any[]): CancelablePromise<{
17
+ data?: Array<DTOComponentRead>;
18
+ pagination?: Pagination;
19
+ }>;
20
+ /**
21
+ * Create a Component
22
+ * Creates a new Component
23
+ * @param requestBody
24
+ * @returns DTOComponentRead When a component is created
25
+ * @throws ApiError
26
+ */
27
+ static componentCreate(requestBody: DTOComponentCreate): CancelablePromise<DTOComponentRead>;
28
+ /**
29
+ * Get Component
30
+ * Get Component via ID
31
+ * @param componentId Id of a component
32
+ * @returns any OK
33
+ * @throws ApiError
34
+ */
35
+ static componentGet(componentId: string): CancelablePromise<any>;
36
+ /**
37
+ * Update Component as New Revision
38
+ * Updates an component as a new revision
39
+ * @param componentId Id of a component
40
+ * @param requestBody
41
+ * @returns DTOComponentRead When a new component is created successfully
42
+ * @throws ApiError
43
+ */
44
+ static componentUpdateAsNewRevision(componentId: string, requestBody: DTOComponentUpdate): CancelablePromise<DTOComponentRead>;
45
+ /**
46
+ * Update Component
47
+ * Updates an component
48
+ * @param componentId Id of a component
49
+ * @param requestBody
50
+ * @returns DTOComponentRead When a component is updated successfully
51
+ * @throws ApiError
52
+ */
53
+ static componentUpdate(componentId: string, requestBody: DTOComponentUpdate): CancelablePromise<DTOComponentRead>;
54
+ /**
55
+ * Delete Component via ID
56
+ * Deletes a specific component given its Id
57
+ * @param componentId Id of a component
58
+ * @returns void
59
+ * @throws ApiError
60
+ */
61
+ static componentDelete(componentId: string): CancelablePromise<void>;
62
+ /**
63
+ * Update Component State
64
+ * Directly update component state. This does not create a new revision
65
+ * @param componentId Id of a component
66
+ * @param requestBody
67
+ * @returns any OK
68
+ * @throws ApiError
69
+ */
70
+ static componentStateUpdate(componentId: string, requestBody: {
71
+ state?: 'published' | 'deprecated' | 'unpublished';
72
+ }): CancelablePromise<any>;
73
+ }
@@ -0,0 +1,171 @@
1
+ import { OpenAPI } from '../core/OpenAPI';
2
+ import { request as __request } from '../core/request';
3
+ export class ComponentService {
4
+ /**
5
+ * List Component
6
+ * List all available component
7
+ * @param page Pagination, starting at page 1
8
+ * @param limit Number of items per page
9
+ * @param sort List of fields to sort by
10
+ * @returns any The list of all component given the parameters used
11
+ * @throws ApiError
12
+ */
13
+ static componentList(page, limit, sort) {
14
+ return __request(OpenAPI, {
15
+ method: 'GET',
16
+ url: '/components',
17
+ query: {
18
+ 'page': page,
19
+ 'limit': limit,
20
+ 'sort': sort,
21
+ },
22
+ errors: {
23
+ 400: `If the filter options or query parameters contain invalid values`,
24
+ 401: `Unauthorized - Missing or invalid Authorization header`,
25
+ 403: `Forbidden - The client is authenticated but not authorized to access this resource`,
26
+ 500: `When an internal server error occurs when listing all related component`,
27
+ },
28
+ });
29
+ }
30
+ /**
31
+ * Create a Component
32
+ * Creates a new Component
33
+ * @param requestBody
34
+ * @returns DTOComponentRead When a component is created
35
+ * @throws ApiError
36
+ */
37
+ static componentCreate(requestBody) {
38
+ return __request(OpenAPI, {
39
+ method: 'POST',
40
+ url: '/components',
41
+ body: requestBody,
42
+ mediaType: 'application/json',
43
+ errors: {
44
+ 400: `If the payload is malformed`,
45
+ 401: `Unauthorized - Missing or invalid Authorization header`,
46
+ 403: `Forbidden - The client is authenticated but not authorized to access this resource`,
47
+ 500: `Internal Server Error`,
48
+ },
49
+ });
50
+ }
51
+ /**
52
+ * Get Component
53
+ * Get Component via ID
54
+ * @param componentId Id of a component
55
+ * @returns any OK
56
+ * @throws ApiError
57
+ */
58
+ static componentGet(componentId) {
59
+ return __request(OpenAPI, {
60
+ method: 'GET',
61
+ url: '/components/{componentId}',
62
+ path: {
63
+ 'componentId': componentId,
64
+ },
65
+ errors: {
66
+ 401: `Unauthorized - Missing or invalid Authorization header`,
67
+ 403: `Forbidden - The client is authenticated but not authorized to access this resource`,
68
+ 404: `If the component does not exist`,
69
+ },
70
+ });
71
+ }
72
+ /**
73
+ * Update Component as New Revision
74
+ * Updates an component as a new revision
75
+ * @param componentId Id of a component
76
+ * @param requestBody
77
+ * @returns DTOComponentRead When a new component is created successfully
78
+ * @throws ApiError
79
+ */
80
+ static componentUpdateAsNewRevision(componentId, requestBody) {
81
+ return __request(OpenAPI, {
82
+ method: 'PATCH',
83
+ url: '/components/{componentId}',
84
+ path: {
85
+ 'componentId': componentId,
86
+ },
87
+ body: requestBody,
88
+ mediaType: 'application/json',
89
+ errors: {
90
+ 400: `If the payload is malformed`,
91
+ 401: `Unauthorized - Missing or invalid Authorization header`,
92
+ 403: `Forbidden - The client is authenticated but not authorized to access this resource`,
93
+ 404: `When the component id to create a new revision from is not found`,
94
+ 500: `When an internal server error occurs updating a component as a new revision`,
95
+ },
96
+ });
97
+ }
98
+ /**
99
+ * Update Component
100
+ * Updates an component
101
+ * @param componentId Id of a component
102
+ * @param requestBody
103
+ * @returns DTOComponentRead When a component is updated successfully
104
+ * @throws ApiError
105
+ */
106
+ static componentUpdate(componentId, requestBody) {
107
+ return __request(OpenAPI, {
108
+ method: 'PUT',
109
+ url: '/components/{componentId}',
110
+ path: {
111
+ 'componentId': componentId,
112
+ },
113
+ body: requestBody,
114
+ mediaType: 'application/json',
115
+ errors: {
116
+ 400: `If the payload is malformed`,
117
+ 401: `Unauthorized - Missing or invalid Authorization header`,
118
+ 403: `Forbidden - The client is authenticated but not authorized to access this resource`,
119
+ 404: `When the component id to update is not found`,
120
+ 500: `When an internal server error occurs updating a component`,
121
+ },
122
+ });
123
+ }
124
+ /**
125
+ * Delete Component via ID
126
+ * Deletes a specific component given its Id
127
+ * @param componentId Id of a component
128
+ * @returns void
129
+ * @throws ApiError
130
+ */
131
+ static componentDelete(componentId) {
132
+ return __request(OpenAPI, {
133
+ method: 'DELETE',
134
+ url: '/components/{componentId}',
135
+ path: {
136
+ 'componentId': componentId,
137
+ },
138
+ errors: {
139
+ 400: `When the component doesn't exist in the first place, or when a before hook fails before deleting the item`,
140
+ 401: `Unauthorized - Missing or invalid Authorization header`,
141
+ 403: `Forbidden - The client is authenticated but not authorized to access this resource`,
142
+ 404: `Not Found`,
143
+ 500: `When the component fails to delete due to an internal server error`,
144
+ },
145
+ });
146
+ }
147
+ /**
148
+ * Update Component State
149
+ * Directly update component state. This does not create a new revision
150
+ * @param componentId Id of a component
151
+ * @param requestBody
152
+ * @returns any OK
153
+ * @throws ApiError
154
+ */
155
+ static componentStateUpdate(componentId, requestBody) {
156
+ return __request(OpenAPI, {
157
+ method: 'GET',
158
+ url: '/components/{componentId}/state',
159
+ path: {
160
+ 'componentId': componentId,
161
+ },
162
+ body: requestBody,
163
+ mediaType: 'application/json',
164
+ errors: {
165
+ 401: `Unauthorized - Missing or invalid Authorization header`,
166
+ 403: `Forbidden - The client is authenticated but not authorized to access this resource`,
167
+ 404: `Not Found`,
168
+ },
169
+ });
170
+ }
171
+ }