@agility/management-sdk 0.1.38 → 0.1.40

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.
@@ -1,192 +1,192 @@
1
- # Multi-Instance Operations
2
-
3
- This guide demonstrates how to perform content operations across multiple Agility CMS instances and locales using configuration-driven approaches.
4
-
5
- ## Overview
6
-
7
- When managing content across multiple Agility CMS instances (different regions, environments, or brands), you can use a configuration matrix to create identical content across multiple instances and locales.
8
-
9
- ## Configuration Structure
10
-
11
- Define your instance matrix using a simple configuration structure:
12
-
13
- ```typescript
14
- interface InstanceConfig {
15
- guid: string;
16
- locales: string[];
17
- name?: string; // Optional: for reporting
18
- region?: string; // Optional: for regional instances
19
- }
20
-
21
- const instances: InstanceConfig[] = [
22
- {
23
- guid: 'xxxxxxx-u',
24
- locales: ['en-us', 'en-ca', 'fr-ca'],
25
- name: 'Production US',
26
- region: 'us'
27
- },
28
- {
29
- guid: 'xxxxxxy-u',
30
- locales: ['en-us'],
31
- name: 'Production EU',
32
- region: 'eu'
33
- }
34
- ];
35
- ```
36
-
37
- ## Basic Multi-Instance Content Creation
38
-
39
- ### Sequential Content Creation
40
-
41
- ```typescript
42
- import * as mgmtApi from '@agility/management-sdk';
43
-
44
- interface ContentCreationResult {
45
- guid: string;
46
- locale: string;
47
- success: boolean;
48
- contentId?: number;
49
- error?: string;
50
- instanceName?: string;
51
- }
52
-
53
- async function createContentAcrossInstances(
54
- instances: InstanceConfig[],
55
- contentData: any
56
- ): Promise<ContentCreationResult[]> {
57
- const apiClient = new mgmtApi.ApiClient();
58
- await apiClient.auth();
59
-
60
- const results: ContentCreationResult[] = [];
61
-
62
- for (const instance of instances) {
63
- for (const locale of instance.locales) {
64
- try {
65
- console.log(`Creating content in ${instance.name || instance.guid} (${locale})...`);
66
-
67
- const contentIds = await apiClient.contentMethods.saveContentItem(
68
- contentData,
69
- instance.guid,
70
- locale
71
- );
72
-
73
- results.push({
74
- guid: instance.guid,
75
- locale,
76
- success: true,
77
- contentId: Array.isArray(contentIds) ? contentIds[0] : contentIds,
78
- instanceName: instance.name
79
- });
80
-
81
- console.log(`✅ Success: Content created with ID ${contentIds} in ${instance.name} (${locale})`);
82
-
83
- } catch (error) {
84
- results.push({
85
- guid: instance.guid,
86
- locale,
87
- success: false,
88
- error: error.message,
89
- instanceName: instance.name
90
- });
91
-
92
- console.error(`❌ Failed: ${instance.name} (${locale}) - ${error.message}`);
93
- }
94
- }
95
- }
96
-
97
- return results;
98
- }
99
-
100
- // Usage
101
- const contentData = {
102
- properties: {
103
- referenceName: 'blog-post',
104
- definitionName: 'BlogPost',
105
- state: 2
106
- },
107
- fields: {
108
- title: 'Global Product Launch Announcement',
109
- content: 'We are excited to announce our new product...',
110
- publishDate: new Date().toISOString(),
111
- author: 'Marketing Team'
112
- }
113
- };
114
-
115
- const results = await createContentAcrossInstances(instances, contentData);
116
- console.log('Content creation completed:', results);
117
- ```
118
-
119
- ### Parallel Processing for Better Performance
120
-
121
- ```typescript
122
- async function createContentParallel(
123
- instances: InstanceConfig[],
124
- contentData: any
125
- ): Promise<ContentCreationResult[]> {
126
- const apiClient = new mgmtApi.ApiClient();
127
- await apiClient.auth();
128
-
129
- // Create array of all instance/locale combinations
130
- const operations = instances.flatMap(instance =>
131
- instance.locales.map(locale => ({ instance, locale }))
132
- );
133
-
134
- // Execute all operations in parallel
135
- const results = await Promise.allSettled(
136
- operations.map(async ({ instance, locale }) => {
137
- try {
138
- const contentIds = await apiClient.contentMethods.saveContentItem(
139
- contentData,
140
- instance.guid,
141
- locale
142
- );
143
-
144
- return {
145
- guid: instance.guid,
146
- locale,
147
- success: true,
148
- contentId: Array.isArray(contentIds) ? contentIds[0] : contentIds,
149
- instanceName: instance.name
150
- } as ContentCreationResult;
151
-
152
- } catch (error) {
153
- return {
154
- guid: instance.guid,
155
- locale,
156
- success: false,
157
- error: error.message,
158
- instanceName: instance.name
159
- } as ContentCreationResult;
160
- }
161
- })
162
- );
163
-
164
- // Extract results from Promise.allSettled
165
- return results.map(result =>
166
- result.status === 'fulfilled' ? result.value : result.reason
167
- );
168
- }
169
-
170
- // Usage
171
- const parallelResults = await createContentParallel(instances, contentData);
172
- console.log('Parallel content creation completed:', parallelResults);
173
- ```
174
-
175
- ---
176
-
177
- ## Navigation
178
- - [← Back to Main Documentation](../README.md)
179
- - [Authentication & Setup](./auth.md)
180
- - [CI/CD & Automated Environments](./cicd.md)
181
- - [AssetMethods](./asset-methods.md)
182
- - [BatchMethods](./batch-methods.md)
183
- - [ContainerMethods](./container-methods.md)
184
- - [ContentMethods](./content-methods.md)
185
- - [InstanceMethods](./instance-methods.md)
186
- - [InstanceUserMethods](./instance-user-methods.md)
187
- - [ModelMethods](./model-methods.md)
188
- - [PageMethods](./page-methods.md)
189
- - [ServerUserMethods](./server-user-methods.md)
190
- - [WebhookMethods](./webhook-methods.md)
191
-
1
+ # Multi-Instance Operations
2
+
3
+ This guide demonstrates how to perform content operations across multiple Agility CMS instances and locales using configuration-driven approaches.
4
+
5
+ ## Overview
6
+
7
+ When managing content across multiple Agility CMS instances (different regions, environments, or brands), you can use a configuration matrix to create identical content across multiple instances and locales.
8
+
9
+ ## Configuration Structure
10
+
11
+ Define your instance matrix using a simple configuration structure:
12
+
13
+ ```typescript
14
+ interface InstanceConfig {
15
+ guid: string;
16
+ locales: string[];
17
+ name?: string; // Optional: for reporting
18
+ region?: string; // Optional: for regional instances
19
+ }
20
+
21
+ const instances: InstanceConfig[] = [
22
+ {
23
+ guid: 'xxxxxxx-u',
24
+ locales: ['en-us', 'en-ca', 'fr-ca'],
25
+ name: 'Production US',
26
+ region: 'us'
27
+ },
28
+ {
29
+ guid: 'xxxxxxy-u',
30
+ locales: ['en-us'],
31
+ name: 'Production EU',
32
+ region: 'eu'
33
+ }
34
+ ];
35
+ ```
36
+
37
+ ## Basic Multi-Instance Content Creation
38
+
39
+ ### Sequential Content Creation
40
+
41
+ ```typescript
42
+ import * as mgmtApi from '@agility/management-sdk';
43
+
44
+ interface ContentCreationResult {
45
+ guid: string;
46
+ locale: string;
47
+ success: boolean;
48
+ contentId?: number;
49
+ error?: string;
50
+ instanceName?: string;
51
+ }
52
+
53
+ async function createContentAcrossInstances(
54
+ instances: InstanceConfig[],
55
+ contentData: any
56
+ ): Promise<ContentCreationResult[]> {
57
+ const apiClient = new mgmtApi.ApiClient();
58
+ await apiClient.auth();
59
+
60
+ const results: ContentCreationResult[] = [];
61
+
62
+ for (const instance of instances) {
63
+ for (const locale of instance.locales) {
64
+ try {
65
+ console.log(`Creating content in ${instance.name || instance.guid} (${locale})...`);
66
+
67
+ const contentIds = await apiClient.contentMethods.saveContentItem(
68
+ contentData,
69
+ instance.guid,
70
+ locale
71
+ );
72
+
73
+ results.push({
74
+ guid: instance.guid,
75
+ locale,
76
+ success: true,
77
+ contentId: Array.isArray(contentIds) ? contentIds[0] : contentIds,
78
+ instanceName: instance.name
79
+ });
80
+
81
+ console.log(`✅ Success: Content created with ID ${contentIds} in ${instance.name} (${locale})`);
82
+
83
+ } catch (error) {
84
+ results.push({
85
+ guid: instance.guid,
86
+ locale,
87
+ success: false,
88
+ error: error.message,
89
+ instanceName: instance.name
90
+ });
91
+
92
+ console.error(`❌ Failed: ${instance.name} (${locale}) - ${error.message}`);
93
+ }
94
+ }
95
+ }
96
+
97
+ return results;
98
+ }
99
+
100
+ // Usage
101
+ const contentData = {
102
+ properties: {
103
+ referenceName: 'blog-post',
104
+ definitionName: 'BlogPost',
105
+ state: 2
106
+ },
107
+ fields: {
108
+ title: 'Global Product Launch Announcement',
109
+ content: 'We are excited to announce our new product...',
110
+ publishDate: new Date().toISOString(),
111
+ author: 'Marketing Team'
112
+ }
113
+ };
114
+
115
+ const results = await createContentAcrossInstances(instances, contentData);
116
+ console.log('Content creation completed:', results);
117
+ ```
118
+
119
+ ### Parallel Processing for Better Performance
120
+
121
+ ```typescript
122
+ async function createContentParallel(
123
+ instances: InstanceConfig[],
124
+ contentData: any
125
+ ): Promise<ContentCreationResult[]> {
126
+ const apiClient = new mgmtApi.ApiClient();
127
+ await apiClient.auth();
128
+
129
+ // Create array of all instance/locale combinations
130
+ const operations = instances.flatMap(instance =>
131
+ instance.locales.map(locale => ({ instance, locale }))
132
+ );
133
+
134
+ // Execute all operations in parallel
135
+ const results = await Promise.allSettled(
136
+ operations.map(async ({ instance, locale }) => {
137
+ try {
138
+ const contentIds = await apiClient.contentMethods.saveContentItem(
139
+ contentData,
140
+ instance.guid,
141
+ locale
142
+ );
143
+
144
+ return {
145
+ guid: instance.guid,
146
+ locale,
147
+ success: true,
148
+ contentId: Array.isArray(contentIds) ? contentIds[0] : contentIds,
149
+ instanceName: instance.name
150
+ } as ContentCreationResult;
151
+
152
+ } catch (error) {
153
+ return {
154
+ guid: instance.guid,
155
+ locale,
156
+ success: false,
157
+ error: error.message,
158
+ instanceName: instance.name
159
+ } as ContentCreationResult;
160
+ }
161
+ })
162
+ );
163
+
164
+ // Extract results from Promise.allSettled
165
+ return results.map(result =>
166
+ result.status === 'fulfilled' ? result.value : result.reason
167
+ );
168
+ }
169
+
170
+ // Usage
171
+ const parallelResults = await createContentParallel(instances, contentData);
172
+ console.log('Parallel content creation completed:', parallelResults);
173
+ ```
174
+
175
+ ---
176
+
177
+ ## Navigation
178
+ - [← Back to Main Documentation](../README.md)
179
+ - [Authentication & Setup](./auth.md)
180
+ - [CI/CD & Automated Environments](./cicd.md)
181
+ - [AssetMethods](./asset-methods.md)
182
+ - [BatchMethods](./batch-methods.md)
183
+ - [ContainerMethods](./container-methods.md)
184
+ - [ContentMethods](./content-methods.md)
185
+ - [InstanceMethods](./instance-methods.md)
186
+ - [InstanceUserMethods](./instance-user-methods.md)
187
+ - [ModelMethods](./model-methods.md)
188
+ - [PageMethods](./page-methods.md)
189
+ - [ServerUserMethods](./server-user-methods.md)
190
+ - [WebhookMethods](./webhook-methods.md)
191
+
192
192