vercel-api-js 0.1.5 → 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.5 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.4s
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 4s
10
+ created dist/index.d.ts in 8s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # vercel-api-js
2
2
 
3
+ ## 0.1.7
4
+
5
+ ### Patch Changes
6
+
7
+ - 64b81ee: Update accessToken helper
8
+
9
+ ## 0.1.6
10
+
11
+ ### Patch Changes
12
+
13
+ - 53e14fe: Add accessToken auth method
14
+
3
15
  ## 0.1.5
4
16
 
5
17
  ### 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) {
@@ -922,14 +934,18 @@ const operationsByTag = {
922
934
  }
923
935
  };
924
936
 
937
+ function formEncoded(data) {
938
+ return Object.entries(data)
939
+ .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
940
+ .join('&');
941
+ }
942
+
925
943
  var _VercelApi_token, _VercelApi_fetch;
926
944
  class VercelApi {
927
945
  constructor(options) {
928
946
  _VercelApi_token.set(this, void 0);
929
947
  _VercelApi_fetch.set(this, void 0);
930
948
  __classPrivateFieldSet(this, _VercelApi_token, options.token, "f");
931
- if (!options.token)
932
- throw new Error('Token is required');
933
949
  __classPrivateFieldSet(this, _VercelApi_fetch, options.fetch || fetch, "f");
934
950
  if (!__classPrivateFieldGet(this, _VercelApi_fetch, "f"))
935
951
  throw new Error('Fetch is required');
@@ -948,14 +964,28 @@ class VercelApi {
948
964
  return undefined;
949
965
  }
950
966
  const method = operationsByTag[namespace][operation];
951
- return (params) => {
952
- return method({ ...params, token, fetchImpl });
967
+ return async (params) => {
968
+ return await method({ ...params, token, fetchImpl });
953
969
  };
954
970
  }
955
971
  });
956
972
  }
957
973
  });
958
974
  }
975
+ get auth() {
976
+ return {
977
+ accessToken: async ({ code, redirectUri, clientId, clientSecret }) => {
978
+ return await fetch$1({
979
+ method: 'POST',
980
+ url: `/v2/oauth/access_token`,
981
+ token: null,
982
+ fetchImpl: __classPrivateFieldGet(this, _VercelApi_fetch, "f"),
983
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
984
+ body: formEncoded({ code, redirect_uri: redirectUri, client_id: clientId, client_secret: clientSecret })
985
+ });
986
+ }
987
+ };
988
+ }
959
989
  async request(endpoint, params) {
960
990
  const [method = '', url = ''] = endpoint.split(' ');
961
991
  const extraParams = (params || {});
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 = {
@@ -15285,6 +15285,9 @@ declare class VercelApi {
15285
15285
  #private;
15286
15286
  constructor(options: VercelApiOptions);
15287
15287
  get api(): ApiProxy;
15288
+ get auth(): {
15289
+ accessToken: ({ code, redirectUri, clientId, clientSecret }: AccessTokenOptions) => Promise<AccessTokenResult>;
15290
+ };
15288
15291
  request<Endpoint extends keyof typeof operationsByPath>(endpoint: Endpoint, params: RequestEndpointParams<Endpoint>): Promise<ReturnType<{
15289
15292
  'POST /v8/artifacts/events': (variables: RecordEventsVariables, signal?: AbortSignal | undefined) => Promise<undefined>;
15290
15293
  'GET /v8/artifacts/status': (variables: StatusVariables, signal?: AbortSignal | undefined) => Promise<StatusResponse>;
@@ -16018,5 +16021,18 @@ declare class VercelApi {
16018
16021
  'POST /v1/edge-config/{edgeConfigId}/token': (variables: CreateEdgeConfigTokenVariables, signal?: AbortSignal | undefined) => Promise<CreateEdgeConfigTokenResponse>;
16019
16022
  }[Endpoint]>>;
16020
16023
  }
16024
+ type AccessTokenOptions = {
16025
+ redirectUri: string;
16026
+ code: string;
16027
+ clientId: string;
16028
+ clientSecret: string;
16029
+ };
16030
+ type AccessTokenResult = {
16031
+ accessToken: string;
16032
+ tokenType: string;
16033
+ installationId: string;
16034
+ userId: string;
16035
+ teamId: string | null;
16036
+ };
16021
16037
 
16022
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) {
@@ -920,14 +932,18 @@ const operationsByTag = {
920
932
  }
921
933
  };
922
934
 
935
+ function formEncoded(data) {
936
+ return Object.entries(data)
937
+ .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
938
+ .join('&');
939
+ }
940
+
923
941
  var _VercelApi_token, _VercelApi_fetch;
924
942
  class VercelApi {
925
943
  constructor(options) {
926
944
  _VercelApi_token.set(this, void 0);
927
945
  _VercelApi_fetch.set(this, void 0);
928
946
  __classPrivateFieldSet(this, _VercelApi_token, options.token, "f");
929
- if (!options.token)
930
- throw new Error('Token is required');
931
947
  __classPrivateFieldSet(this, _VercelApi_fetch, options.fetch || fetch, "f");
932
948
  if (!__classPrivateFieldGet(this, _VercelApi_fetch, "f"))
933
949
  throw new Error('Fetch is required');
@@ -946,14 +962,28 @@ class VercelApi {
946
962
  return undefined;
947
963
  }
948
964
  const method = operationsByTag[namespace][operation];
949
- return (params) => {
950
- return method({ ...params, token, fetchImpl });
965
+ return async (params) => {
966
+ return await method({ ...params, token, fetchImpl });
951
967
  };
952
968
  }
953
969
  });
954
970
  }
955
971
  });
956
972
  }
973
+ get auth() {
974
+ return {
975
+ accessToken: async ({ code, redirectUri, clientId, clientSecret }) => {
976
+ return await fetch$1({
977
+ method: 'POST',
978
+ url: `/v2/oauth/access_token`,
979
+ token: null,
980
+ fetchImpl: __classPrivateFieldGet(this, _VercelApi_fetch, "f"),
981
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
982
+ body: formEncoded({ code, redirect_uri: redirectUri, client_id: clientId, client_secret: clientSecret })
983
+ });
984
+ }
985
+ };
986
+ }
957
987
  async request(endpoint, params) {
958
988
  const [method = '', url = ''] = endpoint.split(' ');
959
989
  const extraParams = (params || {});
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "vercel-api-js",
3
- "version": "0.1.5",
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",