@frontstackdev/cli 0.0.0-canary-20241104114513 → 0.0.0-canary-20241104163513

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.
@@ -7,7 +7,7 @@ import { ofetch } from 'ofetch'
7
7
  import type { BlockEndpoints, BlockParameters, BlockResponses, RequestOptions, BlockQueryFilters, BlockMode, Page } from './generated-types'
8
8
  import type { Query } from './query-types'
9
9
 
10
- type Method = 'GET' | 'POST' | 'PUT' | 'DELETE'
10
+ type Method = 'GET' | 'POST' | 'PATCH' | 'DELETE'
11
11
 
12
12
  const endpoints: BlockEndpoints = {
13
13
  {{#each paths}}
@@ -17,7 +17,7 @@ const endpoints: BlockEndpoints = {
17
17
  {{/each}}
18
18
  }
19
19
 
20
- const invoke = (path: string, method: Method, payload: any, headers: any) => {
20
+ const invoke = async (path: string, method: Method, payload: any, headers: any) => {
21
21
  const _headers: any = {
22
22
  'Content-Type': 'application/json',
23
23
  'Accept': 'application/json',
@@ -25,7 +25,7 @@ const invoke = (path: string, method: Method, payload: any, headers: any) => {
25
25
  'fs-preview-key': '{{components.parameters.FsPreviewKey.schema.enum.[0]}}',
26
26
  {{/if}}
27
27
  {{#if components.parameters.FsSecret.required}}
28
- 'fs-secret': '{{components.parameters.FsSecret.schema.enum.[0]}}'
28
+ 'fs-secret': '{{components.parameters.FsSecret.schema.enum.[0]}}',
29
29
  {{/if}}
30
30
  }
31
31
 
@@ -38,7 +38,7 @@ const invoke = (path: string, method: Method, payload: any, headers: any) => {
38
38
  body: payload
39
39
  }
40
40
 
41
- return ofetch(path, options)
41
+ return await ofetch.raw(path, options)
42
42
  }
43
43
 
44
44
  /* Listing servers, even though only the first one is ever used */
@@ -63,9 +63,9 @@ const client = {
63
63
  * @param blockParameters The parameters to pass to the block
64
64
  * @example { key: '<variant-id>' }
65
65
  * @param config Further configuration options
66
- * @example { query: { filter: { type: 'equals', field: 'name', value: 'Red Dress' } } }
66
+ * @example { query: { filter: [{ type: 'equals', field: 'name', value: 'Red Dress' }] } }
67
67
  */
68
- block: <BlockName extends keyof BlockEndpoints>(
68
+ block: async <BlockName extends keyof BlockEndpoints>(
69
69
  blockName: BlockName,
70
70
  blockParameters: BlockParameters[BlockName],
71
71
  config?: (
@@ -110,7 +110,7 @@ const client = {
110
110
  headers["fs-token"] = config.options.contextKey;
111
111
  }
112
112
 
113
- return invoke(endpoint, 'POST', payload, headers)
113
+ return (await invoke(endpoint, 'POST', payload, headers))._data
114
114
  },
115
115
 
116
116
  /**
@@ -138,7 +138,74 @@ const client = {
138
138
  headers["fs-token"] = config.options.contextKey;
139
139
  }
140
140
 
141
- return invoke(endpoint, 'GET', null, headers)
141
+ return (await invoke(endpoint, 'GET', null, headers))._data
142
+ },
143
+
144
+ /**
145
+ * Fetch a context by its token
146
+ * @param token The token of the context
147
+ * @example 'ae0d4981-c363-4d5a-a49e-1f053d49f2f7'
148
+ *
149
+ * @returns The context and token
150
+ */
151
+ context: async (
152
+ token: ContextToken
153
+ ): Promise<Context> => {
154
+ let endpoint: string = `${servers[0].url}/context/token`;
155
+
156
+ let headers: Record<string, string> = {
157
+ 'fs-token': token
158
+ }
159
+
160
+ return (await invoke(endpoint, 'GET', null, headers))._data
161
+ },
162
+
163
+ /**
164
+ * Fetch a list of contexts
165
+ * @param token The token of the context to fetch
166
+ * @example 'ae0d4981-c363-4d5a-a49e-1f053d49f2f7'
167
+ *
168
+ * @returns The list of contexts and the token
169
+ */
170
+ contextList: async (
171
+ token?: ContextToken
172
+ ): Promise<[Context[], ContextToken]> => {
173
+ let endpoint: string = `${servers[0].url}/context`;
174
+
175
+ const requestHeaders: Record<string, string> = {}
176
+
177
+ if (token) {
178
+ requestHeaders["fs-token"] = token;
179
+ }
180
+
181
+ const {
182
+ _data,
183
+ headers: responseHeaders
184
+ } = await invoke(endpoint, 'GET', null, requestHeaders)
185
+
186
+ return [_data, responseHeaders.get('fs-token')!]
187
+ },
188
+
189
+ /**
190
+ * Update a context
191
+ * @param context The context to update
192
+ * @example { region: 'uk', locale: 'en-GB' }
193
+ * @param token The token of the context to update
194
+ * @example 'ae0d4981-c363-4d5a-a49e-1f053d49f2f7'
195
+ *
196
+ * @returns The updated context
197
+ */
198
+ contextUpdate: async(context: {
199
+ region: string
200
+ locale: string
201
+ }, token: ContextToken): Promise<Context> => {
202
+ let endpoint: string = `${servers[0].url}/context`;
203
+
204
+ let headers: Record<string, string> = {
205
+ 'fs-token': token
206
+ }
207
+
208
+ return (await invoke(endpoint, 'PATCH', context, headers))._data
142
209
  }
143
210
  }
144
211
 
@@ -96,3 +96,33 @@ type BlockMode = {
96
96
  }
97
97
 
98
98
  export type Page = components['schemas']['Page']
99
+
100
+ declare global {
101
+ export type ContextToken = string
102
+
103
+ export type Context = {
104
+ /**
105
+ * The region of the context - e.g. 'uk'
106
+ */
107
+ region: string
108
+ /**
109
+ * The currency of the context - e.g. 'GBP'
110
+ */
111
+ currency: string
112
+ /**
113
+ * List of locales of the context
114
+ */
115
+ locales: Array<Locale>
116
+ }
117
+
118
+ export type Locale = {
119
+ /**
120
+ * The key of the locale - e.g. 'en-GB'
121
+ */
122
+ key: string
123
+ /**
124
+ * The URL configured for the locale - e.g. 'https://my-brand.com/uk/en'
125
+ */
126
+ url: string
127
+ }
128
+ }
package/dist/version CHANGED
@@ -1 +1 @@
1
- 0.0.0-canary-20241104114513
1
+ 0.0.0-canary-20241104163513
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontstackdev/cli",
3
- "version": "0.0.0-canary-20241104114513",
3
+ "version": "0.0.0-canary-20241104163513",
4
4
  "description": "frontstack CLI for managing projects",
5
5
  "type": "module",
6
6
  "module": "dist/frontstack.mjs",