auth0 5.4.0 → 5.6.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/dist/cjs/management/Client.d.ts +12 -0
- package/dist/cjs/management/Client.js +67 -0
- package/dist/cjs/management/api/requests/requests.d.ts +156 -22
- package/dist/cjs/management/api/resources/actions/client/Client.d.ts +2 -2
- package/dist/cjs/management/api/resources/actions/client/Client.js +3 -3
- package/dist/cjs/management/api/resources/actions/resources/triggers/resources/bindings/client/Client.d.ts +2 -2
- package/dist/cjs/management/api/resources/actions/resources/triggers/resources/bindings/client/Client.js +2 -2
- package/dist/cjs/management/api/resources/clientGrants/client/Client.d.ts +0 -1
- package/dist/cjs/management/api/resources/clientGrants/client/Client.js +0 -1
- package/dist/cjs/management/api/resources/clients/client/Client.d.ts +46 -0
- package/dist/cjs/management/api/resources/clients/client/Client.js +146 -1
- package/dist/cjs/management/api/resources/customDomains/client/Client.d.ts +30 -0
- package/dist/cjs/management/api/resources/customDomains/client/Client.js +115 -0
- package/dist/cjs/management/api/resources/groups/client/Client.d.ts +16 -0
- package/dist/cjs/management/api/resources/groups/client/Client.js +57 -0
- package/dist/cjs/management/api/resources/networkAcls/client/Client.d.ts +0 -2
- package/dist/cjs/management/api/resources/networkAcls/client/Client.js +0 -2
- package/dist/cjs/management/api/resources/organizations/client/Client.d.ts +3 -0
- package/dist/cjs/management/api/resources/organizations/client/Client.js +13 -8
- package/dist/cjs/management/api/resources/organizations/resources/connections/client/Client.d.ts +95 -0
- package/dist/cjs/management/api/resources/organizations/resources/connections/client/Client.js +383 -0
- package/dist/cjs/management/api/resources/organizations/resources/connections/client/index.d.ts +1 -0
- package/dist/cjs/management/api/resources/organizations/resources/connections/client/index.js +2 -0
- package/dist/cjs/management/api/resources/organizations/resources/connections/index.d.ts +1 -0
- package/dist/cjs/management/api/resources/organizations/resources/connections/index.js +17 -0
- package/dist/cjs/management/api/resources/organizations/resources/discoveryDomains/client/Client.d.ts +3 -1
- package/dist/cjs/management/api/resources/organizations/resources/discoveryDomains/client/Client.js +3 -1
- package/dist/cjs/management/api/resources/organizations/resources/index.d.ts +1 -0
- package/dist/cjs/management/api/resources/organizations/resources/index.js +2 -1
- package/dist/cjs/management/api/resources/refreshTokens/client/Client.d.ts +23 -0
- package/dist/cjs/management/api/resources/refreshTokens/client/Client.js +88 -0
- package/dist/cjs/management/api/types/types.d.ts +508 -292
- package/dist/cjs/management/api/types/types.js +101 -103
- package/dist/cjs/management/core/auth/BasicAuth.d.ts +2 -2
- package/dist/cjs/management/core/auth/BasicAuth.js +7 -1
- package/dist/cjs/management/core/fetcher/BinaryResponse.d.ts +1 -1
- package/dist/cjs/management/core/fetcher/Fetcher.d.ts +2 -0
- package/dist/cjs/management/core/fetcher/Fetcher.js +5 -1
- package/dist/cjs/management/core/fetcher/index.d.ts +2 -0
- package/dist/cjs/management/core/fetcher/index.js +3 -1
- package/dist/cjs/management/core/fetcher/makePassthroughRequest.d.ts +49 -0
- package/dist/cjs/management/core/fetcher/makePassthroughRequest.js +135 -0
- package/dist/cjs/management/core/fetcher/makeRequest.d.ts +6 -1
- package/dist/cjs/management/core/fetcher/makeRequest.js +30 -9
- package/dist/cjs/management/core/pagination/Page.d.ts +1 -1
- package/dist/cjs/management/core/pagination/index.d.ts +0 -1
- package/dist/cjs/management/core/pagination/index.js +1 -4
- package/dist/cjs/management/core/runtime/runtime.js +8 -7
- package/dist/cjs/management/errors/ManagementError.d.ts +3 -1
- package/dist/cjs/management/errors/ManagementError.js +4 -1
- package/dist/cjs/management/errors/ManagementTimeoutError.d.ts +4 -1
- package/dist/cjs/management/errors/ManagementTimeoutError.js +4 -1
- package/dist/cjs/management/errors/handleNonStatusCodeError.js +4 -1
- package/dist/cjs/management/version.d.ts +1 -1
- package/dist/cjs/management/version.js +1 -1
- package/dist/esm/management/Client.d.mts +12 -0
- package/dist/esm/management/Client.mjs +34 -0
- package/dist/esm/management/api/requests/requests.d.mts +156 -22
- package/dist/esm/management/api/resources/actions/client/Client.d.mts +2 -2
- package/dist/esm/management/api/resources/actions/client/Client.mjs +3 -3
- package/dist/esm/management/api/resources/actions/resources/triggers/resources/bindings/client/Client.d.mts +2 -2
- package/dist/esm/management/api/resources/actions/resources/triggers/resources/bindings/client/Client.mjs +2 -2
- package/dist/esm/management/api/resources/clientGrants/client/Client.d.mts +0 -1
- package/dist/esm/management/api/resources/clientGrants/client/Client.mjs +0 -1
- package/dist/esm/management/api/resources/clients/client/Client.d.mts +46 -0
- package/dist/esm/management/api/resources/clients/client/Client.mjs +146 -1
- package/dist/esm/management/api/resources/customDomains/client/Client.d.mts +30 -0
- package/dist/esm/management/api/resources/customDomains/client/Client.mjs +115 -0
- package/dist/esm/management/api/resources/groups/client/Client.d.mts +16 -0
- package/dist/esm/management/api/resources/groups/client/Client.mjs +57 -0
- package/dist/esm/management/api/resources/networkAcls/client/Client.d.mts +0 -2
- package/dist/esm/management/api/resources/networkAcls/client/Client.mjs +0 -2
- package/dist/esm/management/api/resources/organizations/client/Client.d.mts +3 -0
- package/dist/esm/management/api/resources/organizations/client/Client.mjs +5 -0
- package/dist/esm/management/api/resources/organizations/resources/connections/client/Client.d.mts +95 -0
- package/dist/esm/management/api/resources/organizations/resources/connections/client/Client.mjs +346 -0
- package/dist/esm/management/api/resources/organizations/resources/connections/client/index.d.mts +1 -0
- package/dist/esm/management/api/resources/organizations/resources/connections/client/index.mjs +1 -0
- package/dist/esm/management/api/resources/organizations/resources/connections/index.d.mts +1 -0
- package/dist/esm/management/api/resources/organizations/resources/connections/index.mjs +1 -0
- package/dist/esm/management/api/resources/organizations/resources/discoveryDomains/client/Client.d.mts +3 -1
- package/dist/esm/management/api/resources/organizations/resources/discoveryDomains/client/Client.mjs +3 -1
- package/dist/esm/management/api/resources/organizations/resources/index.d.mts +1 -0
- package/dist/esm/management/api/resources/organizations/resources/index.mjs +1 -0
- package/dist/esm/management/api/resources/refreshTokens/client/Client.d.mts +23 -0
- package/dist/esm/management/api/resources/refreshTokens/client/Client.mjs +88 -0
- package/dist/esm/management/api/types/types.d.mts +508 -292
- package/dist/esm/management/api/types/types.mjs +91 -93
- package/dist/esm/management/core/auth/BasicAuth.d.mts +2 -2
- package/dist/esm/management/core/auth/BasicAuth.mjs +7 -1
- package/dist/esm/management/core/fetcher/BinaryResponse.d.mts +1 -1
- package/dist/esm/management/core/fetcher/Fetcher.d.mts +2 -0
- package/dist/esm/management/core/fetcher/Fetcher.mjs +5 -1
- package/dist/esm/management/core/fetcher/index.d.mts +2 -0
- package/dist/esm/management/core/fetcher/index.mjs +1 -0
- package/dist/esm/management/core/fetcher/makePassthroughRequest.d.mts +49 -0
- package/dist/esm/management/core/fetcher/makePassthroughRequest.mjs +132 -0
- package/dist/esm/management/core/fetcher/makeRequest.d.mts +6 -1
- package/dist/esm/management/core/fetcher/makeRequest.mjs +28 -9
- package/dist/esm/management/core/pagination/Page.d.mts +1 -1
- package/dist/esm/management/core/pagination/index.d.mts +0 -1
- package/dist/esm/management/core/pagination/index.mjs +0 -1
- package/dist/esm/management/core/runtime/runtime.mjs +8 -7
- package/dist/esm/management/errors/ManagementError.d.mts +3 -1
- package/dist/esm/management/errors/ManagementError.mjs +4 -1
- package/dist/esm/management/errors/ManagementTimeoutError.d.mts +4 -1
- package/dist/esm/management/errors/ManagementTimeoutError.mjs +4 -1
- package/dist/esm/management/errors/handleNonStatusCodeError.mjs +4 -1
- package/dist/esm/management/version.d.mts +1 -1
- package/dist/esm/management/version.mjs +1 -1
- package/package.json +5 -6
- package/reference.md +752 -30
- package/dist/cjs/management/core/pagination/CustomPager.d.ts +0 -67
- package/dist/cjs/management/core/pagination/CustomPager.js +0 -194
- package/dist/esm/management/core/pagination/CustomPager.d.mts +0 -67
- package/dist/esm/management/core/pagination/CustomPager.mjs +0 -189
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { BaseRequestOptions, NormalizedClientOptions } from "../../BaseClient.js";
|
|
2
|
-
import type { APIResponse } from "../fetcher/APIResponse.js";
|
|
3
|
-
import type { Fetcher } from "../fetcher/Fetcher.js";
|
|
4
|
-
import type { RawResponse } from "../fetcher/index.js";
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @template TItem The type of the items in the page.
|
|
8
|
-
* @template TResponse The type of the API response.
|
|
9
|
-
*/
|
|
10
|
-
export declare class CustomPager<TItem, TResponse> implements AsyncIterable<TItem> {
|
|
11
|
-
/** The items from the current page */
|
|
12
|
-
data: TItem[];
|
|
13
|
-
/** The raw HTTP response */
|
|
14
|
-
rawResponse: RawResponse;
|
|
15
|
-
/** The parsed response object */
|
|
16
|
-
response: TResponse;
|
|
17
|
-
private sendRequest;
|
|
18
|
-
private nextRequest?;
|
|
19
|
-
private previousRequest?;
|
|
20
|
-
private _hasNextPage;
|
|
21
|
-
private _hasPreviousPage;
|
|
22
|
-
constructor(args: {
|
|
23
|
-
response: TResponse;
|
|
24
|
-
rawResponse: RawResponse;
|
|
25
|
-
items: TItem[];
|
|
26
|
-
hasNextPage: boolean;
|
|
27
|
-
hasPreviousPage: boolean;
|
|
28
|
-
nextRequest?: Fetcher.Args;
|
|
29
|
-
previousRequest?: Fetcher.Args;
|
|
30
|
-
sendRequest: (request: Fetcher.Args) => Promise<APIResponse<TResponse, Fetcher.Error>>;
|
|
31
|
-
});
|
|
32
|
-
/**
|
|
33
|
-
* @returns whether there is a next page to load
|
|
34
|
-
*/
|
|
35
|
-
hasNextPage(): boolean;
|
|
36
|
-
/**
|
|
37
|
-
* @returns whether there is a previous page to load
|
|
38
|
-
*/
|
|
39
|
-
hasPreviousPage(): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Returns the current page data.
|
|
42
|
-
* This is an alias for the `data` property for consistency with other pagination APIs.
|
|
43
|
-
*
|
|
44
|
-
* @returns the items from the current page
|
|
45
|
-
*/
|
|
46
|
-
getCurrentPage(): TItem[];
|
|
47
|
-
/**
|
|
48
|
-
* Retrieves the next page of results.
|
|
49
|
-
* @returns this pager with updated data
|
|
50
|
-
* @throws Error if there is no next page
|
|
51
|
-
*/
|
|
52
|
-
getNextPage(): Promise<this>;
|
|
53
|
-
/**
|
|
54
|
-
* Retrieves the previous page of results.
|
|
55
|
-
* @returns this pager with updated data
|
|
56
|
-
* @throws Error if there is no previous page
|
|
57
|
-
*/
|
|
58
|
-
getPreviousPage(): Promise<this>;
|
|
59
|
-
private iterMessages;
|
|
60
|
-
[Symbol.asyncIterator](): AsyncIterator<TItem, void, unknown>;
|
|
61
|
-
}
|
|
62
|
-
export declare function createCustomPager<TItem, TResponse>({ sendRequest, initialHttpRequest, clientOptions, }: {
|
|
63
|
-
sendRequest: (request: Fetcher.Args) => Promise<APIResponse<TResponse, Fetcher.Error>>;
|
|
64
|
-
initialHttpRequest: Fetcher.Args;
|
|
65
|
-
clientOptions: NormalizedClientOptions;
|
|
66
|
-
requestOptions?: BaseRequestOptions;
|
|
67
|
-
}): Promise<CustomPager<TItem, TResponse>>;
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
12
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
13
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
14
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
15
|
-
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
16
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
17
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
18
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
19
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
20
|
-
function fulfill(value) { resume("next", value); }
|
|
21
|
-
function reject(value) { resume("throw", value); }
|
|
22
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
23
|
-
};
|
|
24
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
25
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
26
|
-
var m = o[Symbol.asyncIterator], i;
|
|
27
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
28
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
29
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
30
|
-
};
|
|
31
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.CustomPager = void 0;
|
|
33
|
-
exports.createCustomPager = createCustomPager;
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
* @template TItem The type of the items in the page.
|
|
37
|
-
* @template TResponse The type of the API response.
|
|
38
|
-
*/
|
|
39
|
-
class CustomPager {
|
|
40
|
-
constructor(args) {
|
|
41
|
-
this.response = args.response;
|
|
42
|
-
this.rawResponse = args.rawResponse;
|
|
43
|
-
this.data = args.items;
|
|
44
|
-
this._hasNextPage = args.hasNextPage;
|
|
45
|
-
this._hasPreviousPage = args.hasPreviousPage;
|
|
46
|
-
this.nextRequest = args.nextRequest;
|
|
47
|
-
this.previousRequest = args.previousRequest;
|
|
48
|
-
this.sendRequest = args.sendRequest;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* @returns whether there is a next page to load
|
|
52
|
-
*/
|
|
53
|
-
hasNextPage() {
|
|
54
|
-
return this._hasNextPage;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* @returns whether there is a previous page to load
|
|
58
|
-
*/
|
|
59
|
-
hasPreviousPage() {
|
|
60
|
-
return this._hasPreviousPage;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Returns the current page data.
|
|
64
|
-
* This is an alias for the `data` property for consistency with other pagination APIs.
|
|
65
|
-
*
|
|
66
|
-
* @returns the items from the current page
|
|
67
|
-
*/
|
|
68
|
-
getCurrentPage() {
|
|
69
|
-
return this.data;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Retrieves the next page of results.
|
|
73
|
-
* @returns this pager with updated data
|
|
74
|
-
* @throws Error if there is no next page
|
|
75
|
-
*/
|
|
76
|
-
getNextPage() {
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
if (!this._hasNextPage || !this.nextRequest) {
|
|
79
|
-
throw new Error("No next page available");
|
|
80
|
-
}
|
|
81
|
-
const response = yield this.sendRequest(this.nextRequest);
|
|
82
|
-
if (!response.ok) {
|
|
83
|
-
const reason = response.error.reason === "status-code" ? `HTTP ${response.error.statusCode}` : response.error.reason;
|
|
84
|
-
throw new Error(`Failed to fetch next page: ${reason}`);
|
|
85
|
-
}
|
|
86
|
-
const data = response.body;
|
|
87
|
-
const rawResponse = response.rawResponse;
|
|
88
|
-
const parsed = yield parse({ request: this.nextRequest, data, rawResponse });
|
|
89
|
-
this.response = data;
|
|
90
|
-
this.rawResponse = rawResponse;
|
|
91
|
-
this.data = parsed.items;
|
|
92
|
-
this._hasNextPage = parsed.hasNextPage;
|
|
93
|
-
this._hasPreviousPage = parsed.hasPreviousPage;
|
|
94
|
-
this.nextRequest = parsed.nextRequest;
|
|
95
|
-
this.previousRequest = parsed.previousRequest;
|
|
96
|
-
return this;
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Retrieves the previous page of results.
|
|
101
|
-
* @returns this pager with updated data
|
|
102
|
-
* @throws Error if there is no previous page
|
|
103
|
-
*/
|
|
104
|
-
getPreviousPage() {
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
if (!this._hasPreviousPage || !this.previousRequest) {
|
|
107
|
-
throw new Error("No previous page available");
|
|
108
|
-
}
|
|
109
|
-
const response = yield this.sendRequest(this.previousRequest);
|
|
110
|
-
if (!response.ok) {
|
|
111
|
-
const reason = response.error.reason === "status-code" ? `HTTP ${response.error.statusCode}` : response.error.reason;
|
|
112
|
-
throw new Error(`Failed to fetch previous page: ${reason}`);
|
|
113
|
-
}
|
|
114
|
-
const data = response.body;
|
|
115
|
-
const rawResponse = response.rawResponse;
|
|
116
|
-
const parsed = yield parse({ request: this.previousRequest, data, rawResponse });
|
|
117
|
-
this.response = data;
|
|
118
|
-
this.rawResponse = rawResponse;
|
|
119
|
-
this.data = parsed.items;
|
|
120
|
-
this._hasNextPage = parsed.hasNextPage;
|
|
121
|
-
this._hasPreviousPage = parsed.hasPreviousPage;
|
|
122
|
-
this.nextRequest = parsed.nextRequest;
|
|
123
|
-
this.previousRequest = parsed.previousRequest;
|
|
124
|
-
return this;
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
iterMessages() {
|
|
128
|
-
return __asyncGenerator(this, arguments, function* iterMessages_1() {
|
|
129
|
-
for (const item of this.data) {
|
|
130
|
-
yield yield __await(item);
|
|
131
|
-
}
|
|
132
|
-
while (this.hasNextPage()) {
|
|
133
|
-
yield __await(this.getNextPage());
|
|
134
|
-
for (const item of this.data) {
|
|
135
|
-
yield yield __await(item);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
[Symbol.asyncIterator]() {
|
|
141
|
-
return __asyncGenerator(this, arguments, function* _a() {
|
|
142
|
-
var _b, e_1, _c, _d;
|
|
143
|
-
try {
|
|
144
|
-
for (var _e = true, _f = __asyncValues(this.iterMessages()), _g; _g = yield __await(_f.next()), _b = _g.done, !_b; _e = true) {
|
|
145
|
-
_d = _g.value;
|
|
146
|
-
_e = false;
|
|
147
|
-
const message = _d;
|
|
148
|
-
yield yield __await(message);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
152
|
-
finally {
|
|
153
|
-
try {
|
|
154
|
-
if (!_e && !_b && (_c = _f.return)) yield __await(_c.call(_f));
|
|
155
|
-
}
|
|
156
|
-
finally { if (e_1) throw e_1.error; }
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
exports.CustomPager = CustomPager;
|
|
162
|
-
function createCustomPager(_a) {
|
|
163
|
-
return __awaiter(this, arguments, void 0, function* ({ sendRequest, initialHttpRequest, clientOptions, }) {
|
|
164
|
-
const response = yield sendRequest(initialHttpRequest);
|
|
165
|
-
if (!response.ok) {
|
|
166
|
-
const reason = response.error.reason === "status-code" ? `HTTP ${response.error.statusCode}` : response.error.reason;
|
|
167
|
-
throw new Error(`Failed to fetch initial page: ${reason}`);
|
|
168
|
-
}
|
|
169
|
-
const data = response.body;
|
|
170
|
-
const rawResponse = response.rawResponse;
|
|
171
|
-
const parsed = yield parse({ request: initialHttpRequest, data, rawResponse });
|
|
172
|
-
return new CustomPager({
|
|
173
|
-
response: data,
|
|
174
|
-
rawResponse,
|
|
175
|
-
items: parsed.items,
|
|
176
|
-
hasNextPage: parsed.hasNextPage,
|
|
177
|
-
hasPreviousPage: parsed.hasPreviousPage,
|
|
178
|
-
nextRequest: parsed.nextRequest,
|
|
179
|
-
previousRequest: parsed.previousRequest,
|
|
180
|
-
sendRequest: sendRequest,
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
function parse(args) {
|
|
185
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
// Placeholder implementation.
|
|
187
|
-
// TODO: Replace this with actual parsing logic.
|
|
188
|
-
return {
|
|
189
|
-
items: [],
|
|
190
|
-
hasNextPage: false,
|
|
191
|
-
hasPreviousPage: false,
|
|
192
|
-
};
|
|
193
|
-
});
|
|
194
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { BaseRequestOptions, NormalizedClientOptions } from "../../BaseClient.mjs";
|
|
2
|
-
import type { APIResponse } from "../fetcher/APIResponse.mjs";
|
|
3
|
-
import type { Fetcher } from "../fetcher/Fetcher.mjs";
|
|
4
|
-
import type { RawResponse } from "../fetcher/index.mjs";
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @template TItem The type of the items in the page.
|
|
8
|
-
* @template TResponse The type of the API response.
|
|
9
|
-
*/
|
|
10
|
-
export declare class CustomPager<TItem, TResponse> implements AsyncIterable<TItem> {
|
|
11
|
-
/** The items from the current page */
|
|
12
|
-
data: TItem[];
|
|
13
|
-
/** The raw HTTP response */
|
|
14
|
-
rawResponse: RawResponse;
|
|
15
|
-
/** The parsed response object */
|
|
16
|
-
response: TResponse;
|
|
17
|
-
private sendRequest;
|
|
18
|
-
private nextRequest?;
|
|
19
|
-
private previousRequest?;
|
|
20
|
-
private _hasNextPage;
|
|
21
|
-
private _hasPreviousPage;
|
|
22
|
-
constructor(args: {
|
|
23
|
-
response: TResponse;
|
|
24
|
-
rawResponse: RawResponse;
|
|
25
|
-
items: TItem[];
|
|
26
|
-
hasNextPage: boolean;
|
|
27
|
-
hasPreviousPage: boolean;
|
|
28
|
-
nextRequest?: Fetcher.Args;
|
|
29
|
-
previousRequest?: Fetcher.Args;
|
|
30
|
-
sendRequest: (request: Fetcher.Args) => Promise<APIResponse<TResponse, Fetcher.Error>>;
|
|
31
|
-
});
|
|
32
|
-
/**
|
|
33
|
-
* @returns whether there is a next page to load
|
|
34
|
-
*/
|
|
35
|
-
hasNextPage(): boolean;
|
|
36
|
-
/**
|
|
37
|
-
* @returns whether there is a previous page to load
|
|
38
|
-
*/
|
|
39
|
-
hasPreviousPage(): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Returns the current page data.
|
|
42
|
-
* This is an alias for the `data` property for consistency with other pagination APIs.
|
|
43
|
-
*
|
|
44
|
-
* @returns the items from the current page
|
|
45
|
-
*/
|
|
46
|
-
getCurrentPage(): TItem[];
|
|
47
|
-
/**
|
|
48
|
-
* Retrieves the next page of results.
|
|
49
|
-
* @returns this pager with updated data
|
|
50
|
-
* @throws Error if there is no next page
|
|
51
|
-
*/
|
|
52
|
-
getNextPage(): Promise<this>;
|
|
53
|
-
/**
|
|
54
|
-
* Retrieves the previous page of results.
|
|
55
|
-
* @returns this pager with updated data
|
|
56
|
-
* @throws Error if there is no previous page
|
|
57
|
-
*/
|
|
58
|
-
getPreviousPage(): Promise<this>;
|
|
59
|
-
private iterMessages;
|
|
60
|
-
[Symbol.asyncIterator](): AsyncIterator<TItem, void, unknown>;
|
|
61
|
-
}
|
|
62
|
-
export declare function createCustomPager<TItem, TResponse>({ sendRequest, initialHttpRequest, clientOptions, }: {
|
|
63
|
-
sendRequest: (request: Fetcher.Args) => Promise<APIResponse<TResponse, Fetcher.Error>>;
|
|
64
|
-
initialHttpRequest: Fetcher.Args;
|
|
65
|
-
clientOptions: NormalizedClientOptions;
|
|
66
|
-
requestOptions?: BaseRequestOptions;
|
|
67
|
-
}): Promise<CustomPager<TItem, TResponse>>;
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
11
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
12
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
14
|
-
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
15
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
16
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
17
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
18
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
19
|
-
function fulfill(value) { resume("next", value); }
|
|
20
|
-
function reject(value) { resume("throw", value); }
|
|
21
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
22
|
-
};
|
|
23
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
24
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
25
|
-
var m = o[Symbol.asyncIterator], i;
|
|
26
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
27
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
28
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
* @template TItem The type of the items in the page.
|
|
33
|
-
* @template TResponse The type of the API response.
|
|
34
|
-
*/
|
|
35
|
-
export class CustomPager {
|
|
36
|
-
constructor(args) {
|
|
37
|
-
this.response = args.response;
|
|
38
|
-
this.rawResponse = args.rawResponse;
|
|
39
|
-
this.data = args.items;
|
|
40
|
-
this._hasNextPage = args.hasNextPage;
|
|
41
|
-
this._hasPreviousPage = args.hasPreviousPage;
|
|
42
|
-
this.nextRequest = args.nextRequest;
|
|
43
|
-
this.previousRequest = args.previousRequest;
|
|
44
|
-
this.sendRequest = args.sendRequest;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* @returns whether there is a next page to load
|
|
48
|
-
*/
|
|
49
|
-
hasNextPage() {
|
|
50
|
-
return this._hasNextPage;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* @returns whether there is a previous page to load
|
|
54
|
-
*/
|
|
55
|
-
hasPreviousPage() {
|
|
56
|
-
return this._hasPreviousPage;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Returns the current page data.
|
|
60
|
-
* This is an alias for the `data` property for consistency with other pagination APIs.
|
|
61
|
-
*
|
|
62
|
-
* @returns the items from the current page
|
|
63
|
-
*/
|
|
64
|
-
getCurrentPage() {
|
|
65
|
-
return this.data;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Retrieves the next page of results.
|
|
69
|
-
* @returns this pager with updated data
|
|
70
|
-
* @throws Error if there is no next page
|
|
71
|
-
*/
|
|
72
|
-
getNextPage() {
|
|
73
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
if (!this._hasNextPage || !this.nextRequest) {
|
|
75
|
-
throw new Error("No next page available");
|
|
76
|
-
}
|
|
77
|
-
const response = yield this.sendRequest(this.nextRequest);
|
|
78
|
-
if (!response.ok) {
|
|
79
|
-
const reason = response.error.reason === "status-code" ? `HTTP ${response.error.statusCode}` : response.error.reason;
|
|
80
|
-
throw new Error(`Failed to fetch next page: ${reason}`);
|
|
81
|
-
}
|
|
82
|
-
const data = response.body;
|
|
83
|
-
const rawResponse = response.rawResponse;
|
|
84
|
-
const parsed = yield parse({ request: this.nextRequest, data, rawResponse });
|
|
85
|
-
this.response = data;
|
|
86
|
-
this.rawResponse = rawResponse;
|
|
87
|
-
this.data = parsed.items;
|
|
88
|
-
this._hasNextPage = parsed.hasNextPage;
|
|
89
|
-
this._hasPreviousPage = parsed.hasPreviousPage;
|
|
90
|
-
this.nextRequest = parsed.nextRequest;
|
|
91
|
-
this.previousRequest = parsed.previousRequest;
|
|
92
|
-
return this;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Retrieves the previous page of results.
|
|
97
|
-
* @returns this pager with updated data
|
|
98
|
-
* @throws Error if there is no previous page
|
|
99
|
-
*/
|
|
100
|
-
getPreviousPage() {
|
|
101
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
if (!this._hasPreviousPage || !this.previousRequest) {
|
|
103
|
-
throw new Error("No previous page available");
|
|
104
|
-
}
|
|
105
|
-
const response = yield this.sendRequest(this.previousRequest);
|
|
106
|
-
if (!response.ok) {
|
|
107
|
-
const reason = response.error.reason === "status-code" ? `HTTP ${response.error.statusCode}` : response.error.reason;
|
|
108
|
-
throw new Error(`Failed to fetch previous page: ${reason}`);
|
|
109
|
-
}
|
|
110
|
-
const data = response.body;
|
|
111
|
-
const rawResponse = response.rawResponse;
|
|
112
|
-
const parsed = yield parse({ request: this.previousRequest, data, rawResponse });
|
|
113
|
-
this.response = data;
|
|
114
|
-
this.rawResponse = rawResponse;
|
|
115
|
-
this.data = parsed.items;
|
|
116
|
-
this._hasNextPage = parsed.hasNextPage;
|
|
117
|
-
this._hasPreviousPage = parsed.hasPreviousPage;
|
|
118
|
-
this.nextRequest = parsed.nextRequest;
|
|
119
|
-
this.previousRequest = parsed.previousRequest;
|
|
120
|
-
return this;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
iterMessages() {
|
|
124
|
-
return __asyncGenerator(this, arguments, function* iterMessages_1() {
|
|
125
|
-
for (const item of this.data) {
|
|
126
|
-
yield yield __await(item);
|
|
127
|
-
}
|
|
128
|
-
while (this.hasNextPage()) {
|
|
129
|
-
yield __await(this.getNextPage());
|
|
130
|
-
for (const item of this.data) {
|
|
131
|
-
yield yield __await(item);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
[Symbol.asyncIterator]() {
|
|
137
|
-
return __asyncGenerator(this, arguments, function* _a() {
|
|
138
|
-
var _b, e_1, _c, _d;
|
|
139
|
-
try {
|
|
140
|
-
for (var _e = true, _f = __asyncValues(this.iterMessages()), _g; _g = yield __await(_f.next()), _b = _g.done, !_b; _e = true) {
|
|
141
|
-
_d = _g.value;
|
|
142
|
-
_e = false;
|
|
143
|
-
const message = _d;
|
|
144
|
-
yield yield __await(message);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
148
|
-
finally {
|
|
149
|
-
try {
|
|
150
|
-
if (!_e && !_b && (_c = _f.return)) yield __await(_c.call(_f));
|
|
151
|
-
}
|
|
152
|
-
finally { if (e_1) throw e_1.error; }
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
export function createCustomPager(_a) {
|
|
158
|
-
return __awaiter(this, arguments, void 0, function* ({ sendRequest, initialHttpRequest, clientOptions, }) {
|
|
159
|
-
const response = yield sendRequest(initialHttpRequest);
|
|
160
|
-
if (!response.ok) {
|
|
161
|
-
const reason = response.error.reason === "status-code" ? `HTTP ${response.error.statusCode}` : response.error.reason;
|
|
162
|
-
throw new Error(`Failed to fetch initial page: ${reason}`);
|
|
163
|
-
}
|
|
164
|
-
const data = response.body;
|
|
165
|
-
const rawResponse = response.rawResponse;
|
|
166
|
-
const parsed = yield parse({ request: initialHttpRequest, data, rawResponse });
|
|
167
|
-
return new CustomPager({
|
|
168
|
-
response: data,
|
|
169
|
-
rawResponse,
|
|
170
|
-
items: parsed.items,
|
|
171
|
-
hasNextPage: parsed.hasNextPage,
|
|
172
|
-
hasPreviousPage: parsed.hasPreviousPage,
|
|
173
|
-
nextRequest: parsed.nextRequest,
|
|
174
|
-
previousRequest: parsed.previousRequest,
|
|
175
|
-
sendRequest: sendRequest,
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
function parse(args) {
|
|
180
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
-
// Placeholder implementation.
|
|
182
|
-
// TODO: Replace this with actual parsing logic.
|
|
183
|
-
return {
|
|
184
|
-
items: [],
|
|
185
|
-
hasNextPage: false,
|
|
186
|
-
hasPreviousPage: false,
|
|
187
|
-
};
|
|
188
|
-
});
|
|
189
|
-
}
|