netlify-api 0.1.1 → 0.1.2

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,10 +1,10 @@
1
1
 
2
- > netlify-api@0.1.1 build /Users/sfera/Workspace/personal/vercel-api/packages/netlify-api
2
+ > netlify-api@0.1.2 build /home/runner/work/openapi-clients/openapi-clients/packages/netlify-api
3
3
  > rimraf dist && rollup -c
4
4
 
5
5
  
6
6
  ./src/index.ts → dist/index.cjs, dist/index.mjs...
7
- created dist/index.cjs, dist/index.mjs in 1.1s
7
+ created dist/index.cjs, dist/index.mjs in 4.9s
8
8
  
9
9
  ./src/index.ts → dist/index.d.ts...
10
- created dist/index.d.ts in 1s
10
+ created dist/index.d.ts in 4.4s
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # netlify-api
2
+
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - ca612f6: Add refresh token helper
8
+ - 719f021: Add base path
package/dist/index.cjs CHANGED
@@ -29,7 +29,7 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
29
29
  }
30
30
 
31
31
  const baseUrl = 'https://api.netlify.com';
32
- async function fetch$1({ url, method, body, headers, pathParams, queryParams, signal, token, fetchImpl }) {
32
+ async function fetch$1({ url, method, body, headers, pathParams, queryParams, signal, token, fetchImpl, basePath }) {
33
33
  try {
34
34
  const requestHeaders = {
35
35
  'Content-Type': 'application/json',
@@ -45,7 +45,7 @@ async function fetch$1({ url, method, body, headers, pathParams, queryParams, si
45
45
  if (requestHeaders['Content-Type']?.toLowerCase().includes('multipart/form-data')) {
46
46
  delete requestHeaders['Content-Type'];
47
47
  }
48
- const response = await fetchImpl(`${baseUrl}${resolveUrl(url, queryParams, pathParams)}`, {
48
+ const response = await fetchImpl(`${baseUrl}${basePath}${resolveUrl(url, queryParams, pathParams)}`, {
49
49
  signal,
50
50
  method: method.toUpperCase(),
51
51
  body: body ? (body instanceof FormData ? body : JSON.stringify(body)) : undefined,
@@ -762,21 +762,24 @@ const operationsByTag = {
762
762
  splitTest: { createSplitTest, getSplitTests, updateSplitTest, getSplitTest, enableSplitTest, disableSplitTest }
763
763
  };
764
764
 
765
- var _NetlifyApi_token, _NetlifyApi_fetch;
765
+ var _NetlifyApi_token, _NetlifyApi_fetch, _NetlifyApi_basePath;
766
766
  class NetlifyApi {
767
767
  constructor(options) {
768
768
  _NetlifyApi_token.set(this, void 0);
769
769
  _NetlifyApi_fetch.set(this, void 0);
770
+ _NetlifyApi_basePath.set(this, void 0);
770
771
  __classPrivateFieldSet(this, _NetlifyApi_token, options.token, "f");
771
772
  if (!options.token)
772
773
  throw new Error('Token is required');
773
774
  __classPrivateFieldSet(this, _NetlifyApi_fetch, options.fetch || fetch, "f");
774
775
  if (!__classPrivateFieldGet(this, _NetlifyApi_fetch, "f"))
775
776
  throw new Error('Fetch is required');
777
+ __classPrivateFieldSet(this, _NetlifyApi_basePath, options.basePath || '/api/v1', "f");
776
778
  }
777
779
  get api() {
778
780
  const token = __classPrivateFieldGet(this, _NetlifyApi_token, "f");
779
781
  const fetchImpl = __classPrivateFieldGet(this, _NetlifyApi_fetch, "f");
782
+ const basePath = __classPrivateFieldGet(this, _NetlifyApi_basePath, "f");
780
783
  return new Proxy({}, {
781
784
  get: (_target, namespace) => {
782
785
  if (operationsByTag[namespace] === undefined) {
@@ -789,14 +792,30 @@ class NetlifyApi {
789
792
  }
790
793
  const method = operationsByTag[namespace][operation];
791
794
  return (params) => {
792
- return method({ ...params, token, fetchImpl });
795
+ return method({ ...params, token, fetchImpl, basePath });
793
796
  };
794
797
  }
795
798
  });
796
799
  }
797
800
  });
798
801
  }
802
+ get auth() {
803
+ return {
804
+ refreshToken: ({ refreshToken, authToken, clientId, clientSecret }) => {
805
+ return __classPrivateFieldGet(this, _NetlifyApi_fetch, "f").call(this, `${baseUrl}/oauth/token`, {
806
+ method: 'POST',
807
+ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${authToken}` },
808
+ body: JSON.stringify({
809
+ grant_type: 'refresh_token',
810
+ refresh_token: refreshToken,
811
+ client_id: clientId,
812
+ client_secret: clientSecret
813
+ })
814
+ });
815
+ }
816
+ };
817
+ }
799
818
  }
800
- _NetlifyApi_token = new WeakMap(), _NetlifyApi_fetch = new WeakMap();
819
+ _NetlifyApi_token = new WeakMap(), _NetlifyApi_fetch = new WeakMap(), _NetlifyApi_basePath = new WeakMap();
801
820
 
802
821
  exports.NetlifyApi = NetlifyApi;
package/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ type FetchImpl = (url: string, init?: RequestInit | undefined) => Promise<Respon
19
19
  type FetcherExtraProps = {
20
20
  token: string;
21
21
  fetchImpl: FetchImpl;
22
+ basePath: string;
22
23
  };
23
24
  type ErrorWrapper<TError> = TError | {
24
25
  status: 'unknown';
@@ -7201,6 +7202,7 @@ type RequiredKeys<T> = {
7201
7202
  interface NetlifyApiOptions {
7202
7203
  token: string;
7203
7204
  fetch?: FetchImpl;
7205
+ basePath?: string;
7204
7206
  }
7205
7207
  type ApiProxy = {
7206
7208
  [Tag in keyof typeof operationsByTag]: {
@@ -7211,7 +7213,16 @@ declare class NetlifyApi {
7211
7213
  #private;
7212
7214
  constructor(options: NetlifyApiOptions);
7213
7215
  get api(): ApiProxy;
7216
+ get auth(): {
7217
+ refreshToken: ({ refreshToken, authToken, clientId, clientSecret }: RefreshTokenOptions) => Promise<Response>;
7218
+ };
7214
7219
  }
7220
+ type RefreshTokenOptions = {
7221
+ refreshToken: string;
7222
+ authToken: string;
7223
+ clientId: string;
7224
+ clientSecret: string;
7225
+ };
7215
7226
 
7216
7227
  /**
7217
7228
  * Generated by @openapi-codegen
package/dist/index.mjs CHANGED
@@ -27,7 +27,7 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
27
27
  }
28
28
 
29
29
  const baseUrl = 'https://api.netlify.com';
30
- async function fetch$1({ url, method, body, headers, pathParams, queryParams, signal, token, fetchImpl }) {
30
+ async function fetch$1({ url, method, body, headers, pathParams, queryParams, signal, token, fetchImpl, basePath }) {
31
31
  try {
32
32
  const requestHeaders = {
33
33
  'Content-Type': 'application/json',
@@ -43,7 +43,7 @@ async function fetch$1({ url, method, body, headers, pathParams, queryParams, si
43
43
  if (requestHeaders['Content-Type']?.toLowerCase().includes('multipart/form-data')) {
44
44
  delete requestHeaders['Content-Type'];
45
45
  }
46
- const response = await fetchImpl(`${baseUrl}${resolveUrl(url, queryParams, pathParams)}`, {
46
+ const response = await fetchImpl(`${baseUrl}${basePath}${resolveUrl(url, queryParams, pathParams)}`, {
47
47
  signal,
48
48
  method: method.toUpperCase(),
49
49
  body: body ? (body instanceof FormData ? body : JSON.stringify(body)) : undefined,
@@ -760,21 +760,24 @@ const operationsByTag = {
760
760
  splitTest: { createSplitTest, getSplitTests, updateSplitTest, getSplitTest, enableSplitTest, disableSplitTest }
761
761
  };
762
762
 
763
- var _NetlifyApi_token, _NetlifyApi_fetch;
763
+ var _NetlifyApi_token, _NetlifyApi_fetch, _NetlifyApi_basePath;
764
764
  class NetlifyApi {
765
765
  constructor(options) {
766
766
  _NetlifyApi_token.set(this, void 0);
767
767
  _NetlifyApi_fetch.set(this, void 0);
768
+ _NetlifyApi_basePath.set(this, void 0);
768
769
  __classPrivateFieldSet(this, _NetlifyApi_token, options.token, "f");
769
770
  if (!options.token)
770
771
  throw new Error('Token is required');
771
772
  __classPrivateFieldSet(this, _NetlifyApi_fetch, options.fetch || fetch, "f");
772
773
  if (!__classPrivateFieldGet(this, _NetlifyApi_fetch, "f"))
773
774
  throw new Error('Fetch is required');
775
+ __classPrivateFieldSet(this, _NetlifyApi_basePath, options.basePath || '/api/v1', "f");
774
776
  }
775
777
  get api() {
776
778
  const token = __classPrivateFieldGet(this, _NetlifyApi_token, "f");
777
779
  const fetchImpl = __classPrivateFieldGet(this, _NetlifyApi_fetch, "f");
780
+ const basePath = __classPrivateFieldGet(this, _NetlifyApi_basePath, "f");
778
781
  return new Proxy({}, {
779
782
  get: (_target, namespace) => {
780
783
  if (operationsByTag[namespace] === undefined) {
@@ -787,14 +790,30 @@ class NetlifyApi {
787
790
  }
788
791
  const method = operationsByTag[namespace][operation];
789
792
  return (params) => {
790
- return method({ ...params, token, fetchImpl });
793
+ return method({ ...params, token, fetchImpl, basePath });
791
794
  };
792
795
  }
793
796
  });
794
797
  }
795
798
  });
796
799
  }
800
+ get auth() {
801
+ return {
802
+ refreshToken: ({ refreshToken, authToken, clientId, clientSecret }) => {
803
+ return __classPrivateFieldGet(this, _NetlifyApi_fetch, "f").call(this, `${baseUrl}/oauth/token`, {
804
+ method: 'POST',
805
+ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${authToken}` },
806
+ body: JSON.stringify({
807
+ grant_type: 'refresh_token',
808
+ refresh_token: refreshToken,
809
+ client_id: clientId,
810
+ client_secret: clientSecret
811
+ })
812
+ });
813
+ }
814
+ };
815
+ }
797
816
  }
798
- _NetlifyApi_token = new WeakMap(), _NetlifyApi_fetch = new WeakMap();
817
+ _NetlifyApi_token = new WeakMap(), _NetlifyApi_fetch = new WeakMap(), _NetlifyApi_basePath = new WeakMap();
799
818
 
800
819
  export { NetlifyApi };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "netlify-api",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Netlify API client for Node.js",
5
5
  "author": "SferaDev",
6
6
  "license": "ISC",
@@ -15,13 +15,13 @@
15
15
  "import": "./dist/index.mjs",
16
16
  "require": "./dist/index.cjs"
17
17
  },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/SferaDev/vercel-api.git"
21
+ },
18
22
  "scripts": {
19
23
  "tsc": "tsc --noEmit",
20
24
  "build": "rimraf dist && rollup -c",
21
25
  "generate": "openapi-codegen netlify"
22
- },
23
- "repository": {
24
- "type": "git",
25
- "url": "git+https://github.com/SferaDev/vercel-api.git"
26
26
  }
27
- }
27
+ }
@@ -1,4 +0,0 @@
1
-
2
- > netlify-api@0.1.1 generate /Users/sfera/Workspace/personal/vercel-api/packages/netlify-api
3
- > openapi-codegen netlify
4
-