@superblocksteam/sdk 0.0.21 → 0.0.22

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.
package/dist/client.d.ts CHANGED
@@ -4,16 +4,17 @@ export interface UploadFile {
4
4
  filename: string;
5
5
  ContentType: string;
6
6
  }
7
- export declare function fetchApplication({ applicationId, token, superblocksBaseUrl, viewMode, }: {
7
+ export declare function fetchApplication({ applicationId, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
8
8
  applicationId: string;
9
9
  token: string;
10
10
  superblocksBaseUrl: string;
11
11
  viewMode: ViewMode;
12
+ injectedHeaders: Record<string, string>;
12
13
  }): Promise<any>;
13
- export declare function fetchApplications(token: string, superblocksBaseUrl: string): Promise<any>;
14
+ export declare function fetchApplications(token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<any>;
14
15
  export declare function fetchApi(apiId: string, token: string, superblocksBaseUrl: string, viewMode: ViewMode): Promise<any>;
15
16
  export declare function fetchApis(token: string, superblocksBaseUrl: string): Promise<any>;
16
- export declare function registerComponents(applicationId: string, componentConfigs: Record<string, any>, token: string, superblocksBaseUrl: string): Promise<any>;
17
+ export declare function registerComponents(applicationId: string, componentConfigs: Record<string, any>, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<any>;
17
18
  export declare function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, }: {
18
19
  applicationId: string;
19
20
  componentConfigs: Record<string, any>;
package/dist/client.js CHANGED
@@ -9,7 +9,8 @@ const FormData = require("form-data");
9
9
  const BASE_SERVER_URL = "api/v1";
10
10
  const BASE_BUCKETEER_URL = "api/v1";
11
11
  const CLI_VERSION_HEADER = "x-superblocks-cli-version";
12
- async function fetchApplication({ applicationId, token, superblocksBaseUrl, viewMode, }) {
12
+ const SUPERBLOCKS_URL_HEADER = "x-superblocks-url";
13
+ async function fetchApplication({ applicationId, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
13
14
  var _a;
14
15
  // TODO(jason) update this with commit ID once we enable fetching by commit
15
16
  const commitId = "latest";
@@ -23,7 +24,8 @@ async function fetchApplication({ applicationId, token, superblocksBaseUrl, view
23
24
  url: componentFileURL,
24
25
  headers: {
25
26
  Authorization: "Bearer " + token,
26
- "x-superblocks-url": superblocksBaseUrl,
27
+ [SUPERBLOCKS_URL_HEADER]: superblocksBaseUrl,
28
+ ...injectedHeaders,
27
29
  },
28
30
  };
29
31
  const response = await (0, axios_1.default)(config);
@@ -37,13 +39,14 @@ async function fetchApplication({ applicationId, token, superblocksBaseUrl, view
37
39
  }
38
40
  }
39
41
  exports.fetchApplication = fetchApplication;
40
- async function fetchApplications(token, superblocksBaseUrl) {
42
+ async function fetchApplications(token, superblocksBaseUrl, injectedHeaders = {}) {
41
43
  try {
42
44
  const config = {
43
45
  method: "get",
44
46
  url: new URL(`/api/v2/applications`, superblocksBaseUrl).toString(),
45
47
  headers: {
46
48
  Authorization: "Bearer " + token,
49
+ ...injectedHeaders,
47
50
  },
48
51
  };
49
52
  const response = await (0, axios_1.default)(config);
@@ -92,7 +95,7 @@ async function fetchApis(token, superblocksBaseUrl) {
92
95
  }
93
96
  }
94
97
  exports.fetchApis = fetchApis;
95
- async function registerComponents(applicationId, componentConfigs, token, superblocksBaseUrl) {
98
+ async function registerComponents(applicationId, componentConfigs, token, superblocksBaseUrl, injectedHeaders) {
96
99
  var _a, _b, _c, _d, _e, _f, _g;
97
100
  try {
98
101
  const [rootSettings] = await (0, util_2.getSuperblocksMonorepoConfigJson)(true);
@@ -102,6 +105,7 @@ async function registerComponents(applicationId, componentConfigs, token, superb
102
105
  headers: {
103
106
  Authorization: "Bearer " + token,
104
107
  [CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
108
+ ...injectedHeaders,
105
109
  },
106
110
  data: { components: componentConfigs },
107
111
  };
@@ -154,7 +158,8 @@ async function uploadComponents({ applicationId, componentConfigs, files, token,
154
158
  headers: {
155
159
  Authorization: "Bearer " + token,
156
160
  [CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
157
- "x-superblocks-url": superblocksBaseUrl,
161
+ [util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.UPLOAD,
162
+ [SUPERBLOCKS_URL_HEADER]: superblocksBaseUrl,
158
163
  ...formHeaders,
159
164
  },
160
165
  };
@@ -179,6 +184,7 @@ async function fetchCurrentUser(token, superblocksBaseUrl) {
179
184
  url: new URL(`/api/v1/users/me`, superblocksBaseUrl).toString(),
180
185
  headers: {
181
186
  Authorization: "Bearer " + token,
187
+ [util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.LOGIN,
182
188
  },
183
189
  };
184
190
  const response = await (0, axios_1.default)(config);
package/dist/sdk.d.ts CHANGED
@@ -3,11 +3,15 @@ export declare class SuperblocksSdk {
3
3
  token: string;
4
4
  superblocksBaseUrl: string;
5
5
  constructor(accessToken: string, superblocksBaseUrl: string);
6
- fetchApplication(applicationId: string, viewMode?: ViewMode): Promise<any>;
7
- fetchApplications(): Promise<any>;
6
+ fetchApplication({ applicationId, headers, viewMode, }: {
7
+ applicationId: string;
8
+ headers?: Record<string, string>;
9
+ viewMode?: ViewMode;
10
+ }): Promise<any>;
11
+ fetchApplications(headers?: Record<string, string>): Promise<any>;
8
12
  fetchApi(apiId: string, viewMode?: ViewMode): Promise<any>;
9
13
  fetchApis(): Promise<any>;
10
- registerComponents(applicationId: string, componentConfigs: Record<string, any>): Promise<any>;
14
+ registerComponents(applicationId: string, componentConfigs: Record<string, any>, injectedHeaders?: Record<string, string>): Promise<any>;
11
15
  uploadComponents(applicationId: string, componentConfigs: Record<string, any>, files: string[]): Promise<any>;
12
16
  fetchCurrentUser(): Promise<any>;
13
17
  }
package/dist/sdk.js CHANGED
@@ -9,16 +9,17 @@ class SuperblocksSdk {
9
9
  this.token = accessToken;
10
10
  this.superblocksBaseUrl = superblocksBaseUrl;
11
11
  }
12
- async fetchApplication(applicationId, viewMode = "export-live") {
12
+ async fetchApplication({ applicationId, headers = {}, viewMode = "export-live", }) {
13
13
  return (0, client_1.fetchApplication)({
14
14
  applicationId,
15
15
  token: this.token,
16
16
  superblocksBaseUrl: this.superblocksBaseUrl,
17
17
  viewMode,
18
+ injectedHeaders: headers,
18
19
  });
19
20
  }
20
- async fetchApplications() {
21
- return (0, client_1.fetchApplications)(this.token, this.superblocksBaseUrl);
21
+ async fetchApplications(headers) {
22
+ return (0, client_1.fetchApplications)(this.token, this.superblocksBaseUrl, headers);
22
23
  }
23
24
  async fetchApi(apiId, viewMode = "export-live") {
24
25
  return (0, client_1.fetchApi)(apiId, this.token, this.superblocksBaseUrl, viewMode);
@@ -26,8 +27,8 @@ class SuperblocksSdk {
26
27
  async fetchApis() {
27
28
  return (0, client_1.fetchApis)(this.token, this.superblocksBaseUrl);
28
29
  }
29
- async registerComponents(applicationId, componentConfigs) {
30
- return (0, client_1.registerComponents)(applicationId, componentConfigs, this.token, this.superblocksBaseUrl);
30
+ async registerComponents(applicationId, componentConfigs, injectedHeaders) {
31
+ return (0, client_1.registerComponents)(applicationId, componentConfigs, this.token, this.superblocksBaseUrl, injectedHeaders);
31
32
  }
32
33
  async uploadComponents(applicationId, componentConfigs, files) {
33
34
  return (0, client_1.uploadComponents)({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/sdk",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Superblocks JS SDK",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
package/src/client.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import * as fs from "fs";
2
2
  import {
3
+ ComponentEvent,
3
4
  getBucketeerUrlFromSuperblocksUrl,
4
5
  getContentType,
6
+ COMPONENT_EVENT_HEADER,
5
7
  } from "@superblocksteam/util";
6
8
  import { getSuperblocksMonorepoConfigJson } from "@superblocksteam/util";
7
9
  import axios, { AxiosError } from "axios";
@@ -11,6 +13,7 @@ const BASE_SERVER_URL = "api/v1";
11
13
  const BASE_BUCKETEER_URL = "api/v1";
12
14
 
13
15
  const CLI_VERSION_HEADER = "x-superblocks-cli-version";
16
+ const SUPERBLOCKS_URL_HEADER = "x-superblocks-url";
14
17
 
15
18
  export type ViewMode = "export-deployed" | "export-latest" | "export-live";
16
19
 
@@ -25,11 +28,13 @@ export async function fetchApplication({
25
28
  token,
26
29
  superblocksBaseUrl,
27
30
  viewMode,
31
+ injectedHeaders = {},
28
32
  }: {
29
33
  applicationId: string;
30
34
  token: string;
31
35
  superblocksBaseUrl: string;
32
36
  viewMode: ViewMode;
37
+ injectedHeaders: Record<string, string>;
33
38
  }) {
34
39
  // TODO(jason) update this with commit ID once we enable fetching by commit
35
40
  const commitId = "latest";
@@ -49,7 +54,8 @@ export async function fetchApplication({
49
54
  url: componentFileURL,
50
55
  headers: {
51
56
  Authorization: "Bearer " + token,
52
- "x-superblocks-url": superblocksBaseUrl,
57
+ [SUPERBLOCKS_URL_HEADER]: superblocksBaseUrl,
58
+ ...injectedHeaders,
53
59
  },
54
60
  };
55
61
  const response = await axios(config);
@@ -64,7 +70,8 @@ export async function fetchApplication({
64
70
 
65
71
  export async function fetchApplications(
66
72
  token: string,
67
- superblocksBaseUrl: string
73
+ superblocksBaseUrl: string,
74
+ injectedHeaders: Record<string, string> = {}
68
75
  ) {
69
76
  try {
70
77
  const config = {
@@ -72,6 +79,7 @@ export async function fetchApplications(
72
79
  url: new URL(`/api/v2/applications`, superblocksBaseUrl).toString(),
73
80
  headers: {
74
81
  Authorization: "Bearer " + token,
82
+ ...injectedHeaders,
75
83
  },
76
84
  };
77
85
  const response = await axios(config);
@@ -128,7 +136,8 @@ export async function registerComponents(
128
136
  applicationId: string,
129
137
  componentConfigs: Record<string, any>,
130
138
  token: string,
131
- superblocksBaseUrl: string
139
+ superblocksBaseUrl: string,
140
+ injectedHeaders?: Record<string, string>
132
141
  ) {
133
142
  try {
134
143
  const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
@@ -141,6 +150,7 @@ export async function registerComponents(
141
150
  headers: {
142
151
  Authorization: "Bearer " + token,
143
152
  [CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
153
+ ...injectedHeaders,
144
154
  },
145
155
  data: { components: componentConfigs },
146
156
  };
@@ -226,7 +236,8 @@ export async function uploadComponents({
226
236
  headers: {
227
237
  Authorization: "Bearer " + token,
228
238
  [CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
229
- "x-superblocks-url": superblocksBaseUrl,
239
+ [COMPONENT_EVENT_HEADER]: ComponentEvent.UPLOAD,
240
+ [SUPERBLOCKS_URL_HEADER]: superblocksBaseUrl,
230
241
  ...formHeaders,
231
242
  },
232
243
  };
@@ -256,6 +267,7 @@ export async function fetchCurrentUser(
256
267
  url: new URL(`/api/v1/users/me`, superblocksBaseUrl).toString(),
257
268
  headers: {
258
269
  Authorization: "Bearer " + token,
270
+ [COMPONENT_EVENT_HEADER]: ComponentEvent.LOGIN,
259
271
  },
260
272
  };
261
273
  const response = await axios(config);
package/src/sdk.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  fetchApi,
3
3
  fetchApis,
4
- fetchApplication,
4
+ fetchApplication as fetchApplicationClient,
5
5
  fetchApplications,
6
6
  registerComponents,
7
7
  uploadComponents,
@@ -18,20 +18,26 @@ export class SuperblocksSdk {
18
18
  this.superblocksBaseUrl = superblocksBaseUrl;
19
19
  }
20
20
 
21
- async fetchApplication(
22
- applicationId: string,
23
- viewMode: ViewMode = "export-live"
24
- ) {
25
- return fetchApplication({
21
+ async fetchApplication({
22
+ applicationId,
23
+ headers = {},
24
+ viewMode = "export-live",
25
+ }: {
26
+ applicationId: string;
27
+ headers?: Record<string, string>;
28
+ viewMode?: ViewMode;
29
+ }) {
30
+ return fetchApplicationClient({
26
31
  applicationId,
27
32
  token: this.token,
28
33
  superblocksBaseUrl: this.superblocksBaseUrl,
29
34
  viewMode,
35
+ injectedHeaders: headers,
30
36
  });
31
37
  }
32
38
 
33
- async fetchApplications() {
34
- return fetchApplications(this.token, this.superblocksBaseUrl);
39
+ async fetchApplications(headers?: Record<string, string>) {
40
+ return fetchApplications(this.token, this.superblocksBaseUrl, headers);
35
41
  }
36
42
 
37
43
  async fetchApi(apiId: string, viewMode: ViewMode = "export-live") {
@@ -44,13 +50,15 @@ export class SuperblocksSdk {
44
50
 
45
51
  async registerComponents(
46
52
  applicationId: string,
47
- componentConfigs: Record<string, any>
53
+ componentConfigs: Record<string, any>,
54
+ injectedHeaders?: Record<string, string>
48
55
  ) {
49
56
  return registerComponents(
50
57
  applicationId,
51
58
  componentConfigs,
52
59
  this.token,
53
- this.superblocksBaseUrl
60
+ this.superblocksBaseUrl,
61
+ injectedHeaders
54
62
  );
55
63
  }
56
64