@@ -11,6 +11,12 @@ import { createReadStream } from 'fs'
11
11
12
12
export function GlobalField ( http , data = { } ) {
13
13
this . stackHeaders = data . stackHeaders
14
+ this . apiVersion = data . api_version || undefined ;
15
+
16
+ if ( this . apiVersion ) {
17
+ http . defaults . headers . api_version = this . apiVersion ;
18
+ http . httpClientParams . headers . api_version = this . apiVersion ;
19
+ }
14
20
this . urlPath = `/global_fields`
15
21
16
22
if ( data . global_field ) {
@@ -36,6 +42,56 @@ export function GlobalField (http, data = {}) {
36
42
*/
37
43
this . update = update ( http , 'global_field' )
38
44
45
+ /**
46
+ * @description The Update GlobalField call lets you update the name and description of an existing GlobalField.
47
+ * @memberof GlobalField
48
+ * @func update
49
+ * @returns {Promise<GlobalField.GlobalField> } Promise for GlobalField instance
50
+ * @example
51
+ * import * as contentstack from '@contentstack/management'
52
+ * const client = contentstack.client()
53
+ * const data = {
54
+ * "global_field": {
55
+ * "title": "Nested Global Field33",
56
+ * "uid": "nested_global_field33",
57
+ * "schema": [
58
+ * {
59
+ * "data_type": "text",
60
+ * "display_name": "Single Line Textbox",
61
+ * "uid": "single_line"
62
+ * },
63
+ * {
64
+ * "data_type": "global_field",
65
+ * "display_name": "Global",
66
+ * "uid": "global_field",
67
+ * "reference_to": "nested_global_field_123"
68
+ * }
69
+ * ]
70
+ * }
71
+ * }
72
+ * client.stack({ api_key: 'api_key'}).globalField('global_field_uid').updateNestedGlobalField(data, { headers: { api_version: '3.2' }})
73
+ * .then((globalField) => {
74
+ console.log(globalField)
75
+ * })
76
+ */
77
+ this . updateNestedGlobalField = async ( config , headers = { } ) => {
78
+ const apiVersion = { api_version : '3.2' }
79
+ this . stackHeaders = { ...this . stackHeaders , ...apiVersion , ...headers }
80
+ try {
81
+ const headers = {
82
+ headers : { ...cloneDeep ( this . stackHeaders ) }
83
+ }
84
+ const response = await http . put ( `${ this . urlPath } ` , config , headers )
85
+ if ( response . data ) {
86
+ return response . data
87
+ } else {
88
+ throw error ( response )
89
+ }
90
+ } catch ( err ) {
91
+ throw error ( err )
92
+ }
93
+ }
94
+
39
95
/**
40
96
* @description The Delete GlobalField call is used to delete an existing GlobalField permanently from your Stack.
41
97
* @memberof GlobalField
@@ -119,8 +175,9 @@ export function GlobalField (http, data = {}) {
119
175
* .then((globalField) => console.log(globalField))
120
176
*
121
177
*/
122
- this . import = async function ( data , params = { } ) {
178
+ this . import = async function ( data , params = { } , headers = { } ) {
123
179
try {
180
+ this . stackHeaders = { ...this . stackHeaders , ...headers } ;
124
181
const response = await upload ( {
125
182
http : http ,
126
183
urlPath : `${ this . urlPath } /import` ,
0 commit comments