netlify 13.2.0 → 13.3.0

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/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { DynamicMethods } from './types.js';
1
2
  type APIOptions = {
2
3
  /** @example 'netlify/js-client' */
3
4
  userAgent?: string;
@@ -16,6 +17,8 @@ type APIOptions = {
16
17
  */
17
18
  globalParams?: Record<string, unknown>;
18
19
  };
20
+ export interface NetlifyAPI extends DynamicMethods {
21
+ }
19
22
  export declare class NetlifyAPI {
20
23
  #private;
21
24
  defaultHeaders: Record<string, string>;
@@ -28,23 +31,13 @@ export declare class NetlifyAPI {
28
31
  constructor(options?: APIOptions);
29
32
  constructor(accessToken: string | undefined, options?: APIOptions);
30
33
  /** Retrieves the access token */
31
- get accessToken(): string | null;
32
- set accessToken(token: string | null);
34
+ get accessToken(): string | undefined | null;
35
+ set accessToken(token: string | undefined | null);
33
36
  get basePath(): string;
34
37
  getAccessToken(ticket: any, { poll, timeout }?: {
35
38
  poll?: number | undefined;
36
39
  timeout?: number | undefined;
37
- }): Promise<string>;
38
- showTicket(_config: {
39
- ticketId: string;
40
- }): Promise<{
41
- authorized: boolean;
42
- }>;
43
- exchangeTicket(_config: {
44
- ticketId: string;
45
- }): Promise<{
46
- access_token: string;
47
- }>;
40
+ }): Promise<string | undefined>;
48
41
  }
49
42
  export declare const methods: any[];
50
43
  export {};
package/lib/index.js CHANGED
@@ -73,15 +73,5 @@ export class NetlifyAPI {
73
73
  this.accessToken = accessTokenResponse.access_token;
74
74
  return accessTokenResponse.access_token;
75
75
  }
76
- // Those methods are getting implemented by the Object.assign(this, { ...methods }) in the constructor
77
- // This is a way where we can still maintain proper types while not implementing them.
78
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
79
- showTicket(_config) {
80
- throw new Error('Will be overridden in constructor!');
81
- }
82
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
83
- exchangeTicket(_config) {
84
- throw new Error('Will be overridden in constructor!');
85
- }
86
76
  }
87
77
  export const methods = getOperations();
package/lib/types.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import type { operations } from '@netlify/open-api';
2
+ /**
3
+ * Converts snake_case to camelCase for TypeScript types.
4
+ */
5
+ type CamelCase<S extends string> = S extends `${infer T}_${infer U}` ? `${T}${Capitalize<CamelCase<U>>}` : S;
6
+ /**
7
+ * Creates a union of both snake_case and camelCase keys with their respective types.
8
+ */
9
+ type SnakeToCamel<T> = {
10
+ [K in keyof T as CamelCase<K & string>]: T[K];
11
+ };
12
+ /**
13
+ * Combines snake_case and camelCase parameters.
14
+ */
15
+ type CombinedCaseParams<T> = SnakeToCamel<T> | T;
16
+ /**
17
+ * Combines `path` and `query` parameters into a single type.
18
+ */
19
+ type OperationParams<K extends keyof operations> = 'parameters' extends keyof operations[K] ? 'path' extends keyof operations[K]['parameters'] ? 'query' extends keyof operations[K]['parameters'] ? CombinedCaseParams<Omit<operations[K]['parameters']['path'], keyof operations[K]['parameters']['query']> & operations[K]['parameters']['query']> : CombinedCaseParams<operations[K]['parameters']['path']> : 'query' extends keyof operations[K]['parameters'] ? CombinedCaseParams<operations[K]['parameters']['query']> : undefined : undefined;
20
+ type SuccessHttpStatusCodes = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;
21
+ /**
22
+ * Extracts the response type from the operation.
23
+ */
24
+ type OperationResponse<K extends keyof operations> = 'responses' extends keyof operations[K] ? SuccessHttpStatusCodes extends infer StatusKeys ? StatusKeys extends keyof operations[K]['responses'] ? 'content' extends keyof operations[K]['responses'][StatusKeys] ? 'application/json' extends keyof operations[K]['responses'][StatusKeys]['content'] ? operations[K]['responses'][StatusKeys]['content']['application/json'] : never : never : never : never : never;
25
+ export type DynamicMethods = {
26
+ [K in keyof operations]: (params: OperationParams<K>) => Promise<OperationResponse<K>>;
27
+ };
28
+ export {};
package/lib/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "netlify",
3
3
  "description": "Netlify Node.js API client",
4
- "version": "13.2.0",
4
+ "version": "13.3.0",
5
5
  "type": "module",
6
6
  "exports": "./lib/index.js",
7
7
  "main": "./lib/index.js",
@@ -46,7 +46,7 @@
46
46
  "micro-api-client": "^3.3.0",
47
47
  "node-fetch": "^3.0.0",
48
48
  "omit.js": "^2.0.2",
49
- "p-wait-for": "^4.0.0",
49
+ "p-wait-for": "^5.0.0",
50
50
  "qs": "^6.9.6"
51
51
  },
52
52
  "devDependencies": {
@@ -63,5 +63,5 @@
63
63
  "engines": {
64
64
  "node": "^14.16.0 || >=16.0.0"
65
65
  },
66
- "gitHead": "c22be640555b4bfbc7b17605af936f7bebf0c212"
66
+ "gitHead": "0a66a5592b80f8b2e2538ebc385d3eea8777c7b7"
67
67
  }