@bacano/sdk 1.1.12 → 1.1.15

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.
@@ -0,0 +1,291 @@
1
+ export type ContentManagementTypeKind = "entry" | "component";
2
+ export type ContentManagementTypeStatus = "draft" | "active" | "archived";
3
+ export type ContentManagementTypeUsage = "website_content" | "product_additional" | "product_specification";
4
+ export type ContentManagementScope = "content_types:manage" | "content_entries:manage" | "content_media:upload" | "content_entries:publish";
5
+ export type ContentManagementFieldType = "boolean" | "component" | "date" | "link" | "measure" | "media" | "number" | "reference" | "repeater" | "rich_text" | "rich_text_full" | "select" | "slug" | "text" | "textarea";
6
+ export interface ContentManagementChildFieldInput {
7
+ id?: string | null;
8
+ key: string;
9
+ label: string;
10
+ type: ContentManagementFieldType;
11
+ required?: boolean;
12
+ sortOrder: number;
13
+ settings?: Record<string, unknown>;
14
+ componentKey?: string | null;
15
+ }
16
+ export interface ContentManagementFieldInput extends ContentManagementChildFieldInput {
17
+ sectionKey?: string | null;
18
+ children?: ContentManagementChildFieldInput[];
19
+ }
20
+ export interface ContentManagementTypeInput {
21
+ key: string;
22
+ name: string;
23
+ description?: string;
24
+ kind: ContentManagementTypeKind;
25
+ status?: "draft" | "active";
26
+ settings?: Record<string, unknown>;
27
+ usages?: ContentManagementTypeUsage[];
28
+ sections?: Array<{
29
+ key: string;
30
+ title: string;
31
+ description?: string;
32
+ sortOrder: number;
33
+ }>;
34
+ specificationScopes?: Array<{
35
+ category?: string | null;
36
+ subcategoryId?: string | null;
37
+ }>;
38
+ deletedPaths?: string[];
39
+ confirmDestructiveChanges?: boolean;
40
+ fields?: ContentManagementFieldInput[];
41
+ }
42
+ export interface ContentManagementType extends Omit<ContentManagementTypeInput, "status"> {
43
+ id: string;
44
+ companyId: string;
45
+ description: string;
46
+ status: ContentManagementTypeStatus;
47
+ settings: Record<string, unknown>;
48
+ usages: ContentManagementTypeUsage[];
49
+ sections: Array<{
50
+ id: string;
51
+ key: string;
52
+ title: string;
53
+ description: string;
54
+ sortOrder: number;
55
+ }>;
56
+ specificationScopes: Array<{
57
+ id: string;
58
+ category: string | null;
59
+ subcategoryId: string | null;
60
+ }>;
61
+ fields: ContentManagementFieldInput[];
62
+ createdAt: string;
63
+ updatedAt: string;
64
+ }
65
+ export interface ContentManagementContext {
66
+ companyId: string;
67
+ /** @deprecated Use scopes to inspect the complete grant. */
68
+ scope: "content_types:manage";
69
+ scopes: ContentManagementScope[];
70
+ expiresAt: string;
71
+ }
72
+ export type ContentManagementEntryStatus = "draft" | "published" | "archived";
73
+ export interface ContentManagementEntryInput {
74
+ contentType: string;
75
+ key: string;
76
+ name: string;
77
+ locale?: string;
78
+ categoryKey?: string;
79
+ categoryName?: string;
80
+ status?: Exclude<ContentManagementEntryStatus, "archived">;
81
+ tagIds?: string[];
82
+ content?: Record<string, unknown>;
83
+ expectedUpdatedAt?: string;
84
+ }
85
+ export interface ContentManagementEntry {
86
+ id: string;
87
+ companyId: string;
88
+ contentType: {
89
+ id: string;
90
+ key: string;
91
+ name: string;
92
+ };
93
+ key: string;
94
+ name: string;
95
+ locale: string;
96
+ categoryKey: string;
97
+ status: ContentManagementEntryStatus;
98
+ tagIds: string[];
99
+ tags: string[];
100
+ content: Record<string, unknown>;
101
+ publishedAt: string | null;
102
+ createdAt: string;
103
+ updatedAt: string;
104
+ }
105
+ export interface ContentManagementEntryListInput {
106
+ contentType?: string;
107
+ locale?: string;
108
+ status?: ContentManagementEntryStatus;
109
+ limit?: number;
110
+ offset?: number;
111
+ }
112
+ export interface ContentManagementEntryList {
113
+ entries: ContentManagementEntry[];
114
+ total: number;
115
+ }
116
+ export interface ContentManagementMedia {
117
+ id: string;
118
+ fileId: string;
119
+ name: string;
120
+ mediaKind: "image";
121
+ mimeType: string;
122
+ sizeBytes: number;
123
+ width: number | null;
124
+ height: number | null;
125
+ altText: string;
126
+ createdAt: string;
127
+ }
128
+ export interface ContentManagementMediaListInput {
129
+ search?: string;
130
+ limit?: number;
131
+ offset?: number;
132
+ }
133
+ export interface ContentManagementMediaList {
134
+ items: ContentManagementMedia[];
135
+ total: number;
136
+ }
137
+ export interface ContentManagementImageUploadInput {
138
+ file: Blob | ArrayBuffer | Uint8Array;
139
+ fileName: string;
140
+ altText?: string;
141
+ }
142
+ export interface ContentManagementImageUploadResult extends ContentManagementMedia {
143
+ reused: boolean;
144
+ }
145
+ export interface ContentManagementReferences {
146
+ categories: Array<{
147
+ code: string;
148
+ name: string;
149
+ subcategories: Array<{
150
+ id: string;
151
+ name: string;
152
+ }>;
153
+ }>;
154
+ optionLists: Array<{
155
+ key: string;
156
+ name: string;
157
+ isExtensible: boolean;
158
+ options: Array<{
159
+ value: string;
160
+ label: string;
161
+ }>;
162
+ }>;
163
+ measureDimensions: Array<{
164
+ code: string;
165
+ name: string;
166
+ canonicalUnitCode: string;
167
+ units: Array<{
168
+ code: string;
169
+ name: string;
170
+ symbol: string;
171
+ }>;
172
+ }>;
173
+ }
174
+ export type ContentManagementGroupStatus = "active" | "inactive";
175
+ export interface ContentManagementGroupInput {
176
+ key: string;
177
+ name: string;
178
+ description?: string;
179
+ sortOrder?: number;
180
+ status?: ContentManagementGroupStatus;
181
+ }
182
+ export interface ContentManagementGroup {
183
+ id: string;
184
+ companyId: string;
185
+ key: string;
186
+ name: string;
187
+ description: string;
188
+ sortOrder: number;
189
+ status: ContentManagementGroupStatus;
190
+ createdAt: string;
191
+ updatedAt: string;
192
+ }
193
+ export type ContentManagementOptionListStatus = "draft" | "active" | "archived";
194
+ export interface ContentManagementOptionListItemInput {
195
+ id?: string | null;
196
+ value: string;
197
+ label: string;
198
+ parentItemId?: string | null;
199
+ sortOrder: number;
200
+ isActive?: boolean;
201
+ metadata?: Record<string, unknown>;
202
+ }
203
+ export interface ContentManagementOptionListInput {
204
+ key: string;
205
+ name: string;
206
+ description?: string;
207
+ status?: Exclude<ContentManagementOptionListStatus, "archived">;
208
+ parentListId?: string | null;
209
+ isExtensible?: boolean;
210
+ confirmDestructiveChanges?: boolean;
211
+ items?: ContentManagementOptionListItemInput[];
212
+ }
213
+ export interface ContentManagementOptionListItem {
214
+ id: string;
215
+ value: string;
216
+ label: string;
217
+ parentItemId: string | null;
218
+ sortOrder: number;
219
+ isActive: boolean;
220
+ metadata: Record<string, unknown>;
221
+ createdAt: string;
222
+ updatedAt: string;
223
+ }
224
+ export interface ContentManagementOptionList {
225
+ id: string;
226
+ companyId: string;
227
+ key: string;
228
+ name: string;
229
+ description: string;
230
+ status: ContentManagementOptionListStatus;
231
+ parentListId: string | null;
232
+ isExtensible: boolean;
233
+ items: ContentManagementOptionListItem[];
234
+ createdAt: string;
235
+ updatedAt: string;
236
+ }
237
+ export type ContentManagementLifecycleOperation = "archive" | "restore" | "delete";
238
+ export interface ContentManagementLifecycleResult {
239
+ success: boolean;
240
+ allowed: boolean;
241
+ applied: boolean;
242
+ entity_id: string | null;
243
+ entity_type: "type" | "component" | "entry" | "group" | "option_list" | null;
244
+ operation: ContentManagementLifecycleOperation | null;
245
+ name: string | null;
246
+ status: string | null;
247
+ dependencies: Array<{
248
+ code: string;
249
+ label: string;
250
+ count: number;
251
+ blocking: boolean;
252
+ }>;
253
+ message: string | null;
254
+ errors: string[];
255
+ }
256
+ export type ContentManagementAccessTokenProvider = () => string | Promise<string>;
257
+ export interface ContentManagementClientConfig {
258
+ apiUrl: string;
259
+ accessToken: string | ContentManagementAccessTokenProvider;
260
+ fetch?: typeof fetch;
261
+ }
262
+ export interface ContentManagementClient {
263
+ getContext(): Promise<ContentManagementContext>;
264
+ getReferences(): Promise<ContentManagementReferences>;
265
+ listTypes(): Promise<ContentManagementType[]>;
266
+ getType(identifier: string): Promise<ContentManagementType>;
267
+ createType(input: ContentManagementTypeInput): Promise<ContentManagementType>;
268
+ updateType(identifier: string, input: ContentManagementTypeInput): Promise<ContentManagementType>;
269
+ inspectLifecycle(identifier: string, operation: ContentManagementLifecycleOperation): Promise<ContentManagementLifecycleResult>;
270
+ applyLifecycle(identifier: string, operation: ContentManagementLifecycleOperation): Promise<ContentManagementLifecycleResult>;
271
+ listEntries(input?: ContentManagementEntryListInput): Promise<ContentManagementEntryList>;
272
+ getEntry(identifier: string, locale?: string): Promise<ContentManagementEntry>;
273
+ createEntry(input: ContentManagementEntryInput): Promise<ContentManagementEntry>;
274
+ updateEntry(identifier: string, input: ContentManagementEntryInput): Promise<ContentManagementEntry>;
275
+ inspectEntryLifecycle(identifier: string, operation: ContentManagementLifecycleOperation): Promise<ContentManagementLifecycleResult>;
276
+ applyEntryLifecycle(identifier: string, operation: ContentManagementLifecycleOperation): Promise<ContentManagementLifecycleResult>;
277
+ listMedia(input?: ContentManagementMediaListInput): Promise<ContentManagementMediaList>;
278
+ uploadImage(input: ContentManagementImageUploadInput): Promise<ContentManagementImageUploadResult>;
279
+ listGroups(): Promise<ContentManagementGroup[]>;
280
+ getGroup(identifier: string): Promise<ContentManagementGroup>;
281
+ createGroup(input: ContentManagementGroupInput): Promise<ContentManagementGroup>;
282
+ updateGroup(identifier: string, input: ContentManagementGroupInput): Promise<ContentManagementGroup>;
283
+ inspectGroupLifecycle(identifier: string, operation: ContentManagementLifecycleOperation): Promise<ContentManagementLifecycleResult>;
284
+ applyGroupLifecycle(identifier: string, operation: ContentManagementLifecycleOperation): Promise<ContentManagementLifecycleResult>;
285
+ listOptionLists(): Promise<ContentManagementOptionList[]>;
286
+ getOptionList(identifier: string): Promise<ContentManagementOptionList>;
287
+ createOptionList(input: ContentManagementOptionListInput): Promise<ContentManagementOptionList>;
288
+ updateOptionList(identifier: string, input: ContentManagementOptionListInput): Promise<ContentManagementOptionList>;
289
+ inspectOptionListLifecycle(identifier: string, operation: ContentManagementLifecycleOperation): Promise<ContentManagementLifecycleResult>;
290
+ applyOptionListLifecycle(identifier: string, operation: ContentManagementLifecycleOperation): Promise<ContentManagementLifecycleResult>;
291
+ }
@@ -58,6 +58,34 @@ function encodeIdentifier(identifier) {
58
58
  }
59
59
  return encodeURIComponent(normalized);
60
60
  }
61
+ function entryListPath(input = {}) {
62
+ const search = new URLSearchParams();
63
+ if (input.contentType) search.set("contentType", input.contentType);
64
+ if (input.locale) search.set("locale", input.locale);
65
+ if (input.status) search.set("status", input.status);
66
+ if (input.limit !== void 0) search.set("limit", String(input.limit));
67
+ if (input.offset !== void 0) search.set("offset", String(input.offset));
68
+ const query = search.toString();
69
+ return query ? `/entries?${query}` : "/entries";
70
+ }
71
+ function mediaListPath(input = {}) {
72
+ const search = new URLSearchParams();
73
+ if (input.search) search.set("search", input.search);
74
+ if (input.limit !== void 0) search.set("limit", String(input.limit));
75
+ if (input.offset !== void 0) search.set("offset", String(input.offset));
76
+ const query = search.toString();
77
+ return query ? `/media?${query}` : "/media";
78
+ }
79
+ function uploadBody(file) {
80
+ if ("arrayBuffer" in file) return file;
81
+ if (file instanceof ArrayBuffer) return file;
82
+ const bytes = new Uint8Array(file.byteLength);
83
+ bytes.set(file);
84
+ return bytes.buffer;
85
+ }
86
+ function encodedHeader(value) {
87
+ return encodeURIComponent(value.trim());
88
+ }
61
89
  function createContentManagementClient(config) {
62
90
  const apiUrl = normalizeApiUrl(config.apiUrl);
63
91
  const fetchImplementation = config.fetch ?? globalThis.fetch;
@@ -88,7 +116,7 @@ function createContentManagementClient(config) {
88
116
  headers: {
89
117
  Accept: "application/json",
90
118
  Authorization: `Bearer ${await getAccessToken()}`,
91
- ...init?.body ? { "Content-Type": "application/json" } : {},
119
+ ...typeof init?.body === "string" ? { "Content-Type": "application/json" } : {},
92
120
  ...init?.headers
93
121
  }
94
122
  }
@@ -109,8 +137,8 @@ function createContentManagementClient(config) {
109
137
  }
110
138
  return payload.data;
111
139
  };
112
- const lifecycle = (identifier, operation, dryRun) => request(
113
- `/types/${encodeIdentifier(identifier)}/lifecycle`,
140
+ const lifecycle = (resource, identifier, operation, dryRun) => request(
141
+ `/${resource}/${encodeIdentifier(identifier)}/lifecycle`,
114
142
  {
115
143
  method: "POST",
116
144
  body: JSON.stringify({ operation, dryRun })
@@ -129,7 +157,81 @@ function createContentManagementClient(config) {
129
157
  method: "PUT",
130
158
  body: JSON.stringify(input)
131
159
  }),
132
- inspectLifecycle: (identifier, operation) => lifecycle(identifier, operation, true),
133
- applyLifecycle: (identifier, operation) => lifecycle(identifier, operation, false)
160
+ inspectLifecycle: (identifier, operation) => lifecycle("types", identifier, operation, true),
161
+ applyLifecycle: (identifier, operation) => lifecycle("types", identifier, operation, false),
162
+ listEntries: (input) => request(entryListPath(input)),
163
+ getEntry: (identifier, locale) => {
164
+ const query = locale ? `?locale=${encodeURIComponent(locale.trim())}` : "";
165
+ return request(
166
+ `/entries/${encodeIdentifier(identifier)}${query}`
167
+ );
168
+ },
169
+ createEntry: (input) => request("/entries", {
170
+ method: "POST",
171
+ body: JSON.stringify(input)
172
+ }),
173
+ updateEntry: (identifier, input) => request(
174
+ `/entries/${encodeIdentifier(identifier)}`,
175
+ {
176
+ method: "PUT",
177
+ body: JSON.stringify(input)
178
+ }
179
+ ),
180
+ inspectEntryLifecycle: (identifier, operation) => lifecycle("entries", identifier, operation, true),
181
+ applyEntryLifecycle: (identifier, operation) => lifecycle("entries", identifier, operation, false),
182
+ listMedia: (input) => request(mediaListPath(input)),
183
+ uploadImage: (input) => {
184
+ const fileName = input.fileName.trim();
185
+ if (!fileName) {
186
+ throw new ContentManagementError({
187
+ message: "A descriptive image file name is required.",
188
+ code: "CONTENT_MEDIA_FILE_NAME_REQUIRED",
189
+ status: 0
190
+ });
191
+ }
192
+ return request("/media/images", {
193
+ method: "POST",
194
+ headers: {
195
+ "Content-Type": "application/octet-stream",
196
+ "X-Bacano-File-Name": encodedHeader(fileName),
197
+ ...input.altText ? { "X-Bacano-Alt-Text": encodedHeader(input.altText) } : {}
198
+ },
199
+ body: uploadBody(input.file)
200
+ });
201
+ },
202
+ listGroups: () => request("/groups"),
203
+ getGroup: (identifier) => request(
204
+ `/groups/${encodeIdentifier(identifier)}`
205
+ ),
206
+ createGroup: (input) => request("/groups", {
207
+ method: "POST",
208
+ body: JSON.stringify(input)
209
+ }),
210
+ updateGroup: (identifier, input) => request(
211
+ `/groups/${encodeIdentifier(identifier)}`,
212
+ {
213
+ method: "PUT",
214
+ body: JSON.stringify(input)
215
+ }
216
+ ),
217
+ inspectGroupLifecycle: (identifier, operation) => lifecycle("groups", identifier, operation, true),
218
+ applyGroupLifecycle: (identifier, operation) => lifecycle("groups", identifier, operation, false),
219
+ listOptionLists: () => request("/option-lists"),
220
+ getOptionList: (identifier) => request(
221
+ `/option-lists/${encodeIdentifier(identifier)}`
222
+ ),
223
+ createOptionList: (input) => request("/option-lists", {
224
+ method: "POST",
225
+ body: JSON.stringify(input)
226
+ }),
227
+ updateOptionList: (identifier, input) => request(
228
+ `/option-lists/${encodeIdentifier(identifier)}`,
229
+ {
230
+ method: "PUT",
231
+ body: JSON.stringify(input)
232
+ }
233
+ ),
234
+ inspectOptionListLifecycle: (identifier, operation) => lifecycle("option-lists", identifier, operation, true),
235
+ applyOptionListLifecycle: (identifier, operation) => lifecycle("option-lists", identifier, operation, false)
134
236
  };
135
237
  }
@@ -1,125 +1,5 @@
1
- export type ContentManagementTypeKind = "entry" | "component";
2
- export type ContentManagementTypeStatus = "draft" | "active" | "archived";
3
- export type ContentManagementTypeUsage = "website_content" | "product_additional" | "product_specification";
4
- export type ContentManagementFieldType = "boolean" | "component" | "date" | "link" | "measure" | "media" | "number" | "reference" | "repeater" | "rich_text" | "rich_text_full" | "select" | "slug" | "text" | "textarea";
5
- export interface ContentManagementChildFieldInput {
6
- id?: string | null;
7
- key: string;
8
- label: string;
9
- type: ContentManagementFieldType;
10
- required?: boolean;
11
- sortOrder: number;
12
- settings?: Record<string, unknown>;
13
- componentKey?: string | null;
14
- }
15
- export interface ContentManagementFieldInput extends ContentManagementChildFieldInput {
16
- sectionKey?: string | null;
17
- children?: ContentManagementChildFieldInput[];
18
- }
19
- export interface ContentManagementTypeInput {
20
- key: string;
21
- name: string;
22
- description?: string;
23
- kind: ContentManagementTypeKind;
24
- status?: "draft" | "active";
25
- settings?: Record<string, unknown>;
26
- usages?: ContentManagementTypeUsage[];
27
- sections?: Array<{
28
- key: string;
29
- title: string;
30
- description?: string;
31
- sortOrder: number;
32
- }>;
33
- specificationScopes?: Array<{
34
- category?: string | null;
35
- subcategoryId?: string | null;
36
- }>;
37
- deletedPaths?: string[];
38
- confirmDestructiveChanges?: boolean;
39
- fields?: ContentManagementFieldInput[];
40
- }
41
- export interface ContentManagementType extends Omit<ContentManagementTypeInput, "status"> {
42
- id: string;
43
- companyId: string;
44
- description: string;
45
- status: ContentManagementTypeStatus;
46
- settings: Record<string, unknown>;
47
- usages: ContentManagementTypeUsage[];
48
- sections: Array<{
49
- id: string;
50
- key: string;
51
- title: string;
52
- description: string;
53
- sortOrder: number;
54
- }>;
55
- specificationScopes: Array<{
56
- id: string;
57
- category: string | null;
58
- subcategoryId: string | null;
59
- }>;
60
- fields: ContentManagementFieldInput[];
61
- createdAt: string;
62
- updatedAt: string;
63
- }
64
- export interface ContentManagementContext {
65
- companyId: string;
66
- scope: "content_types:manage";
67
- expiresAt: string;
68
- }
69
- export interface ContentManagementReferences {
70
- categories: Array<{
71
- code: string;
72
- name: string;
73
- subcategories: Array<{
74
- id: string;
75
- name: string;
76
- }>;
77
- }>;
78
- optionLists: Array<{
79
- key: string;
80
- name: string;
81
- isExtensible: boolean;
82
- options: Array<{
83
- value: string;
84
- label: string;
85
- }>;
86
- }>;
87
- measureDimensions: Array<{
88
- code: string;
89
- name: string;
90
- canonicalUnitCode: string;
91
- units: Array<{
92
- code: string;
93
- name: string;
94
- symbol: string;
95
- }>;
96
- }>;
97
- }
98
- export type ContentManagementLifecycleOperation = "archive" | "restore" | "delete";
99
- export interface ContentManagementLifecycleResult {
100
- success: boolean;
101
- allowed: boolean;
102
- applied: boolean;
103
- entity_id: string | null;
104
- entity_type: "type" | "component" | null;
105
- operation: ContentManagementLifecycleOperation | null;
106
- name: string | null;
107
- status: string | null;
108
- dependencies: Array<{
109
- code: string;
110
- label: string;
111
- count: number;
112
- blocking: boolean;
113
- }>;
114
- message: string | null;
115
- errors: string[];
116
- }
117
- export type ContentManagementAccessTokenProvider = () => string | Promise<string>;
118
- export interface ContentManagementClientConfig {
119
- apiUrl: string;
120
- accessToken: string | ContentManagementAccessTokenProvider;
121
- fetch?: typeof fetch;
122
- }
1
+ import type { ContentManagementClient, ContentManagementClientConfig } from "./content-management-types";
2
+ export * from "./content-management-types";
123
3
  export declare class ContentManagementError extends Error {
124
4
  readonly code: string;
125
5
  readonly status: number;
@@ -131,14 +11,4 @@ export declare class ContentManagementError extends Error {
131
11
  details?: unknown;
132
12
  });
133
13
  }
134
- export interface ContentManagementClient {
135
- getContext(): Promise<ContentManagementContext>;
136
- getReferences(): Promise<ContentManagementReferences>;
137
- listTypes(): Promise<ContentManagementType[]>;
138
- getType(identifier: string): Promise<ContentManagementType>;
139
- createType(input: ContentManagementTypeInput): Promise<ContentManagementType>;
140
- updateType(identifier: string, input: ContentManagementTypeInput): Promise<ContentManagementType>;
141
- inspectLifecycle(identifier: string, operation: ContentManagementLifecycleOperation): Promise<ContentManagementLifecycleResult>;
142
- applyLifecycle(identifier: string, operation: ContentManagementLifecycleOperation): Promise<ContentManagementLifecycleResult>;
143
- }
144
14
  export declare function createContentManagementClient(config: ContentManagementClientConfig): ContentManagementClient;