vercel-api-js 0.1.6 → 0.1.7

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,16 +1,10 @@
1
1
 
2
- > vercel-api-js@0.1.6 build /home/runner/work/openapi-clients/openapi-clients/packages/vercel-api-js
2
+ > vercel-api-js@0.1.7 build /home/runner/work/openapi-clients/openapi-clients/packages/vercel-api-js
3
3
  > rimraf dist && rollup -c
4
4
 
5
5
  
6
6
  ./src/index.ts → dist/index.cjs, dist/index.mjs...
7
- (!) Plugin typescript: @rollup/plugin-typescript TS6133: 'key' is declared but its value is never read.
8
- openapi-codegen.config.ts: (106:67)
9
- 
10
- 106 const updatedOpenAPIDocument = JSON.stringify(openAPIDocument, (key, value) => {
11
-    ~~~
12
- 
13
- created dist/index.cjs, dist/index.mjs in 4.3s
7
+ created dist/index.cjs, dist/index.mjs in 9.5s
14
8
  
15
9
  ./src/index.ts → dist/index.d.ts...
16
- created dist/index.d.ts in 4.7s
10
+ created dist/index.d.ts in 8s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # vercel-api-js
2
2
 
3
+ ## 0.1.7
4
+
5
+ ### Patch Changes
6
+
7
+ - 64b81ee: Update accessToken helper
8
+
3
9
  ## 0.1.6
4
10
 
5
11
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -28,14 +28,21 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
28
28
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
29
29
  }
30
30
 
31
+ function notEmpty(value) {
32
+ return value !== null && value !== undefined;
33
+ }
34
+ function compactObject(obj) {
35
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
36
+ }
37
+
31
38
  const baseUrl = 'https://api.vercel.com';
32
39
  async function fetch$1({ url, method, body, headers, pathParams, queryParams, signal, token, fetchImpl }) {
33
40
  try {
34
- const requestHeaders = {
41
+ const requestHeaders = compactObject({
35
42
  'Content-Type': 'application/json',
36
- Authorization: `Bearer ${token}`,
43
+ Authorization: token ? `Bearer ${token}` : undefined,
37
44
  ...headers
38
- };
45
+ });
39
46
  /**
40
47
  * As the fetch API is being used, when multipart/form-data is specified
41
48
  * the Content-Type header must be deleted so that the browser can set
@@ -45,10 +52,15 @@ async function fetch$1({ url, method, body, headers, pathParams, queryParams, si
45
52
  if (requestHeaders['Content-Type']?.toLowerCase().includes('multipart/form-data')) {
46
53
  delete requestHeaders['Content-Type'];
47
54
  }
55
+ const payload = body instanceof FormData
56
+ ? body
57
+ : requestHeaders['Content-Type'] === 'application/json'
58
+ ? JSON.stringify(body)
59
+ : body;
48
60
  const response = await fetchImpl(`${baseUrl}${resolveUrl(url, queryParams, pathParams)}`, {
49
61
  signal,
50
62
  method: method.toUpperCase(),
51
- body: body ? (body instanceof FormData ? body : JSON.stringify(body)) : undefined,
63
+ body: payload,
52
64
  headers: requestHeaders
53
65
  });
54
66
  if (!response.ok) {
@@ -934,8 +946,6 @@ class VercelApi {
934
946
  _VercelApi_token.set(this, void 0);
935
947
  _VercelApi_fetch.set(this, void 0);
936
948
  __classPrivateFieldSet(this, _VercelApi_token, options.token, "f");
937
- if (!options.token)
938
- throw new Error('Token is required');
939
949
  __classPrivateFieldSet(this, _VercelApi_fetch, options.fetch || fetch, "f");
940
950
  if (!__classPrivateFieldGet(this, _VercelApi_fetch, "f"))
941
951
  throw new Error('Fetch is required');
@@ -965,8 +975,11 @@ class VercelApi {
965
975
  get auth() {
966
976
  return {
967
977
  accessToken: async ({ code, redirectUri, clientId, clientSecret }) => {
968
- return await __classPrivateFieldGet(this, _VercelApi_fetch, "f").call(this, `${baseUrl}/v2/oauth/access_token`, {
978
+ return await fetch$1({
969
979
  method: 'POST',
980
+ url: `/v2/oauth/access_token`,
981
+ token: null,
982
+ fetchImpl: __classPrivateFieldGet(this, _VercelApi_fetch, "f"),
970
983
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
971
984
  body: formEncoded({ code, redirect_uri: redirectUri, client_id: clientId, client_secret: clientSecret })
972
985
  });
package/dist/index.d.ts CHANGED
@@ -930,7 +930,7 @@ type Response = {
930
930
  type FetchImpl = (url: string, init?: RequestInit | undefined) => Promise<Response>;
931
931
 
932
932
  type FetcherExtraProps = {
933
- token: string;
933
+ token: string | null;
934
934
  fetchImpl: FetchImpl;
935
935
  };
936
936
  type ErrorWrapper<TError> = TError | {
@@ -15272,7 +15272,7 @@ type RequiredKeys<T> = {
15272
15272
  }[keyof T];
15273
15273
 
15274
15274
  interface VercelApiOptions {
15275
- token: string;
15275
+ token: string | null;
15276
15276
  fetch?: FetchImpl;
15277
15277
  }
15278
15278
  type ApiProxy = {
@@ -15286,7 +15286,7 @@ declare class VercelApi {
15286
15286
  constructor(options: VercelApiOptions);
15287
15287
  get api(): ApiProxy;
15288
15288
  get auth(): {
15289
- accessToken: ({ code, redirectUri, clientId, clientSecret }: AccessTokenOptions) => Promise<Response>;
15289
+ accessToken: ({ code, redirectUri, clientId, clientSecret }: AccessTokenOptions) => Promise<AccessTokenResult>;
15290
15290
  };
15291
15291
  request<Endpoint extends keyof typeof operationsByPath>(endpoint: Endpoint, params: RequestEndpointParams<Endpoint>): Promise<ReturnType<{
15292
15292
  'POST /v8/artifacts/events': (variables: RecordEventsVariables, signal?: AbortSignal | undefined) => Promise<undefined>;
@@ -16027,5 +16027,12 @@ type AccessTokenOptions = {
16027
16027
  clientId: string;
16028
16028
  clientSecret: string;
16029
16029
  };
16030
+ type AccessTokenResult = {
16031
+ accessToken: string;
16032
+ tokenType: string;
16033
+ installationId: string;
16034
+ userId: string;
16035
+ teamId: string | null;
16036
+ };
16030
16037
 
16031
16038
  export { components as Components, schemas as Schemas, VercelApi, VercelApiOptions };
package/dist/index.mjs CHANGED
@@ -26,14 +26,21 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
26
26
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
27
27
  }
28
28
 
29
+ function notEmpty(value) {
30
+ return value !== null && value !== undefined;
31
+ }
32
+ function compactObject(obj) {
33
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
34
+ }
35
+
29
36
  const baseUrl = 'https://api.vercel.com';
30
37
  async function fetch$1({ url, method, body, headers, pathParams, queryParams, signal, token, fetchImpl }) {
31
38
  try {
32
- const requestHeaders = {
39
+ const requestHeaders = compactObject({
33
40
  'Content-Type': 'application/json',
34
- Authorization: `Bearer ${token}`,
41
+ Authorization: token ? `Bearer ${token}` : undefined,
35
42
  ...headers
36
- };
43
+ });
37
44
  /**
38
45
  * As the fetch API is being used, when multipart/form-data is specified
39
46
  * the Content-Type header must be deleted so that the browser can set
@@ -43,10 +50,15 @@ async function fetch$1({ url, method, body, headers, pathParams, queryParams, si
43
50
  if (requestHeaders['Content-Type']?.toLowerCase().includes('multipart/form-data')) {
44
51
  delete requestHeaders['Content-Type'];
45
52
  }
53
+ const payload = body instanceof FormData
54
+ ? body
55
+ : requestHeaders['Content-Type'] === 'application/json'
56
+ ? JSON.stringify(body)
57
+ : body;
46
58
  const response = await fetchImpl(`${baseUrl}${resolveUrl(url, queryParams, pathParams)}`, {
47
59
  signal,
48
60
  method: method.toUpperCase(),
49
- body: body ? (body instanceof FormData ? body : JSON.stringify(body)) : undefined,
61
+ body: payload,
50
62
  headers: requestHeaders
51
63
  });
52
64
  if (!response.ok) {
@@ -932,8 +944,6 @@ class VercelApi {
932
944
  _VercelApi_token.set(this, void 0);
933
945
  _VercelApi_fetch.set(this, void 0);
934
946
  __classPrivateFieldSet(this, _VercelApi_token, options.token, "f");
935
- if (!options.token)
936
- throw new Error('Token is required');
937
947
  __classPrivateFieldSet(this, _VercelApi_fetch, options.fetch || fetch, "f");
938
948
  if (!__classPrivateFieldGet(this, _VercelApi_fetch, "f"))
939
949
  throw new Error('Fetch is required');
@@ -963,8 +973,11 @@ class VercelApi {
963
973
  get auth() {
964
974
  return {
965
975
  accessToken: async ({ code, redirectUri, clientId, clientSecret }) => {
966
- return await __classPrivateFieldGet(this, _VercelApi_fetch, "f").call(this, `${baseUrl}/v2/oauth/access_token`, {
976
+ return await fetch$1({
967
977
  method: 'POST',
978
+ url: `/v2/oauth/access_token`,
979
+ token: null,
980
+ fetchImpl: __classPrivateFieldGet(this, _VercelApi_fetch, "f"),
968
981
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
969
982
  body: formEncoded({ code, redirect_uri: redirectUri, client_id: clientId, client_secret: clientSecret })
970
983
  });
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "vercel-api-js",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Vercel API client for Node.js",
5
5
  "author": "SferaDev",
6
6
  "license": "ISC",
7
7
  "bugs": {
8
- "url": "https://github.com/SferaDev/vercel-api/issues"
8
+ "url": "https://github.com/SferaDev/openapi-clients/issues"
9
9
  },
10
- "homepage": "https://github.com/SferaDev/vercel-api#readme",
10
+ "homepage": "https://github.com/SferaDev/openapi-clients#readme",
11
11
  "main": "dist/index.cjs",
12
12
  "module": "dist/index.mjs",
13
13
  "typings": "dist/index.d.ts",
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",
20
- "url": "git+https://github.com/SferaDev/vercel-api.git"
20
+ "url": "git+https://github.com/SferaDev/openapi-clients.git"
21
21
  },
22
22
  "scripts": {
23
23
  "tsc": "tsc --noEmit",