@nextplus/js-sdk 0.0.1 → 0.0.4
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/README.md +228 -0
- package/dist/chunk-DNVJS7WW.js +20836 -0
- package/dist/chunk-FXXZNC42.js +726 -0
- package/dist/index.d.ts +34 -209
- package/dist/index.js +244 -27585
- package/dist/sdk/client/index.d.ts +39 -0
- package/dist/sdk/client/index.js +18 -0
- package/dist/sdk/sdk.gen.d.ts +34568 -0
- package/dist/sdk/sdk.gen.js +213 -0
- package/dist/types.gen-vDP9AbtO.d.ts +258 -0
- package/openapi-ts.config.ts +36 -0
- package/package.json +32 -74
- package/prettier.config.js +5 -0
- package/src/index.ts +219 -0
- package/src/sdk/client/client.gen.ts +199 -0
- package/src/sdk/client/index.ts +25 -0
- package/src/sdk/client/types.gen.ts +232 -0
- package/src/sdk/client/utils.gen.ts +424 -0
- package/src/sdk/client.gen.ts +28 -0
- package/src/sdk/core/auth.gen.ts +42 -0
- package/src/sdk/core/bodySerializer.gen.ts +90 -0
- package/src/sdk/core/params.gen.ts +153 -0
- package/src/sdk/core/pathSerializer.gen.ts +181 -0
- package/src/sdk/core/types.gen.ts +120 -0
- package/src/sdk/index.ts +3 -0
- package/src/sdk/schemas.gen.ts +6968 -0
- package/src/sdk/sdk.gen.ts +31790 -0
- package/src/sdk/transformers.gen.ts +8383 -0
- package/src/sdk/types.gen.ts +40708 -0
- package/src/smoke.ts +74 -0
- package/tsconfig.json +23 -0
- package/tsconfig.node.json +11 -0
- package/LICENSE +0 -19
- package/dist/core/ApiError.d.ts +0 -10
- package/dist/core/ApiRequestOptions.d.ts +0 -13
- package/dist/core/ApiResult.d.ts +0 -7
- package/dist/core/CancelablePromise.d.ts +0 -20
- package/dist/core/OpenAPI.d.ts +0 -16
- package/dist/core/request.d.ts +0 -30
- package/dist/index.d.mts +0 -15467
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -27586
- package/dist/index.mjs.map +0 -1
- package/dist/models/ACL.d.ts +0 -19
- package/dist/models/AIPrompt.d.ts +0 -13
- package/dist/models/AccessToken.d.ts +0 -12
- package/dist/models/ApiMethod.d.ts +0 -13
- package/dist/models/ApiMethodLog.d.ts +0 -14
- package/dist/models/BreakType.d.ts +0 -10
- package/dist/models/Catalog.d.ts +0 -16
- package/dist/models/Category.d.ts +0 -10
- package/dist/models/Certificate.d.ts +0 -12
- package/dist/models/CertificateMapping.d.ts +0 -11
- package/dist/models/Chapter.d.ts +0 -6
- package/dist/models/Comment.d.ts +0 -13
- package/dist/models/Configuration.d.ts +0 -16
- package/dist/models/Connection.d.ts +0 -10
- package/dist/models/Connector.d.ts +0 -9
- package/dist/models/ConnectorFunction.d.ts +0 -13
- package/dist/models/ContentPackage.d.ts +0 -24
- package/dist/models/ContentPackageSession.d.ts +0 -12
- package/dist/models/ContentPackageView.d.ts +0 -11
- package/dist/models/CustomField.d.ts +0 -18
- package/dist/models/Device.d.ts +0 -10
- package/dist/models/DeviceFamily.d.ts +0 -12
- package/dist/models/Document.d.ts +0 -24
- package/dist/models/Event.d.ts +0 -15
- package/dist/models/Field.d.ts +0 -33
- package/dist/models/FileParser.d.ts +0 -15
- package/dist/models/FileParserJob.d.ts +0 -12
- package/dist/models/FileParserStrategyJob.d.ts +0 -15
- package/dist/models/Folder.d.ts +0 -9
- package/dist/models/Form.d.ts +0 -35
- package/dist/models/FormData.d.ts +0 -55
- package/dist/models/FormDataComment.d.ts +0 -13
- package/dist/models/Forum.d.ts +0 -12
- package/dist/models/Gateway.d.ts +0 -17
- package/dist/models/Group.d.ts +0 -8
- package/dist/models/InventoryTransaction.d.ts +0 -19
- package/dist/models/Kit.d.ts +0 -17
- package/dist/models/List.d.ts +0 -10
- package/dist/models/ListItem.d.ts +0 -13
- package/dist/models/Location.d.ts +0 -13
- package/dist/models/Menus.d.ts +0 -10
- package/dist/models/NPS.d.ts +0 -16
- package/dist/models/Node.d.ts +0 -32
- package/dist/models/ObjectID.d.ts +0 -1
- package/dist/models/OpcUaServer.d.ts +0 -15
- package/dist/models/Operation.d.ts +0 -15
- package/dist/models/Pages.d.ts +0 -11
- package/dist/models/Part.d.ts +0 -10
- package/dist/models/PartAssembly.d.ts +0 -55
- package/dist/models/PartAssemblyDocument.d.ts +0 -9
- package/dist/models/Post.d.ts +0 -16
- package/dist/models/PrintPreset.d.ts +0 -26
- package/dist/models/PriorityLabel.d.ts +0 -12
- package/dist/models/ProductionEntity.d.ts +0 -18
- package/dist/models/ProductionEntityEvent.d.ts +0 -21
- package/dist/models/ProductionEntityMapping.d.ts +0 -16
- package/dist/models/ProductionEntityTransaction.d.ts +0 -19
- package/dist/models/ProductionEntityType.d.ts +0 -10
- package/dist/models/Project.d.ts +0 -10
- package/dist/models/Resource.d.ts +0 -26
- package/dist/models/ResourceMapping.d.ts +0 -9
- package/dist/models/Revision.d.ts +0 -8
- package/dist/models/Role.d.ts +0 -8
- package/dist/models/RoleMapping.d.ts +0 -17
- package/dist/models/Rule.d.ts +0 -11
- package/dist/models/ScromSession.d.ts +0 -11
- package/dist/models/Shift.d.ts +0 -26
- package/dist/models/ShiftType.d.ts +0 -28
- package/dist/models/Station.d.ts +0 -11
- package/dist/models/Stock.d.ts +0 -56
- package/dist/models/StockItem.d.ts +0 -7
- package/dist/models/SyncClients.d.ts +0 -12
- package/dist/models/SyncHistory.d.ts +0 -12
- package/dist/models/Table.d.ts +0 -11
- package/dist/models/TableSetup.d.ts +0 -18
- package/dist/models/TimeLog.d.ts +0 -7
- package/dist/models/TimeLogReport.d.ts +0 -29
- package/dist/models/Timeline.d.ts +0 -17
- package/dist/models/Tool.d.ts +0 -18
- package/dist/models/Translation.d.ts +0 -12
- package/dist/models/Unit.d.ts +0 -11
- package/dist/models/UpdateInfo.d.ts +0 -9
- package/dist/models/UserModel.d.ts +0 -70
- package/dist/models/UserPreferences.d.ts +0 -6
- package/dist/models/Variant.d.ts +0 -13
- package/dist/models/VoteMapping.d.ts +0 -12
- package/dist/models/Warehouse.d.ts +0 -9
- package/dist/models/Webhook.d.ts +0 -15
- package/dist/models/Wire.d.ts +0 -12
- package/dist/models/Wiringlist.d.ts +0 -15
- package/dist/models/Workflow.d.ts +0 -54
- package/dist/models/WorkflowDetails.d.ts +0 -9
- package/dist/models/WorkflowNote.d.ts +0 -18
- package/dist/models/WorkflowSessionItem.d.ts +0 -56
- package/dist/models/WorkflowType.d.ts +0 -17
- package/dist/models/Workorder.d.ts +0 -94
- package/dist/models/WorkorderAction.d.ts +0 -8
- package/dist/models/WorkorderStatus.d.ts +0 -22
- package/dist/models/WorkorderTemplate.d.ts +0 -23
- package/dist/models/meta.d.ts +0 -5
- package/dist/models/x_any.d.ts +0 -1
- package/dist/services/AclService.d.ts +0 -133
- package/dist/services/AiPromptService.d.ts +0 -133
- package/dist/services/AiService.d.ts +0 -12
- package/dist/services/ApiMethodLogService.d.ts +0 -133
- package/dist/services/ApiMethodService.d.ts +0 -140
- package/dist/services/BomService.d.ts +0 -18
- package/dist/services/BreakService.d.ts +0 -19
- package/dist/services/BreakTypeService.d.ts +0 -42
- package/dist/services/CatalogService.d.ts +0 -267
- package/dist/services/CategoryService.d.ts +0 -74
- package/dist/services/CertificateMappingService.d.ts +0 -60
- package/dist/services/CertificateService.d.ts +0 -74
- package/dist/services/ChapterService.d.ts +0 -34
- package/dist/services/CommentService.d.ts +0 -58
- package/dist/services/ConfigurationService.d.ts +0 -49
- package/dist/services/ConnectionService.d.ts +0 -20
- package/dist/services/ConnectorFunctionService.d.ts +0 -149
- package/dist/services/ConnectorService.d.ts +0 -201
- package/dist/services/ContainerService.d.ts +0 -66
- package/dist/services/ContentPackageService.d.ts +0 -115
- package/dist/services/ContentPackageSessionService.d.ts +0 -28
- package/dist/services/ContentPackageViewService.d.ts +0 -165
- package/dist/services/CustomFieldService.d.ts +0 -57
- package/dist/services/DeviceFamilyService.d.ts +0 -64
- package/dist/services/DeviceService.d.ts +0 -21
- package/dist/services/DigestEmailService.d.ts +0 -8
- package/dist/services/DocumentService.d.ts +0 -103
- package/dist/services/EventService.d.ts +0 -20
- package/dist/services/FieldService.d.ts +0 -86
- package/dist/services/FileParserJobService.d.ts +0 -49
- package/dist/services/FileParserService.d.ts +0 -78
- package/dist/services/FileParserStrategyJobService.d.ts +0 -49
- package/dist/services/FolderService.d.ts +0 -50
- package/dist/services/FormDataCommentService.d.ts +0 -159
- package/dist/services/FormDataService.d.ts +0 -242
- package/dist/services/FormService.d.ts +0 -82
- package/dist/services/ForumService.d.ts +0 -49
- package/dist/services/GatewayService.d.ts +0 -59
- package/dist/services/GroupService.d.ts +0 -50
- package/dist/services/IntegrationBuilderService.d.ts +0 -23
- package/dist/services/InventoryTransactionService.d.ts +0 -151
- package/dist/services/LastSeenResourceService.d.ts +0 -16
- package/dist/services/ListItemService.d.ts +0 -96
- package/dist/services/ListService.d.ts +0 -73
- package/dist/services/LocationService.d.ts +0 -80
- package/dist/services/MenusService.d.ts +0 -180
- package/dist/services/NodeService.d.ts +0 -383
- package/dist/services/NpsService.d.ts +0 -56
- package/dist/services/OpcUaServerService.d.ts +0 -182
- package/dist/services/OperationService.d.ts +0 -60
- package/dist/services/PagesService.d.ts +0 -151
- package/dist/services/PartAssemblyDocumentService.d.ts +0 -12
- package/dist/services/PartAssemblyService.d.ts +0 -400
- package/dist/services/PartService.d.ts +0 -133
- package/dist/services/PostService.d.ts +0 -56
- package/dist/services/PrintPresetService.d.ts +0 -155
- package/dist/services/PriorityLabelService.d.ts +0 -45
- package/dist/services/PriorityService.d.ts +0 -51
- package/dist/services/ProductionEntityEventService.d.ts +0 -169
- package/dist/services/ProductionEntityMappingService.d.ts +0 -142
- package/dist/services/ProductionEntityService.d.ts +0 -207
- package/dist/services/ProductionEntityTransactionService.d.ts +0 -142
- package/dist/services/ProductionEntityTypeService.d.ts +0 -151
- package/dist/services/ProjectService.d.ts +0 -142
- package/dist/services/PythonResultService.d.ts +0 -15
- package/dist/services/ResourceMappingService.d.ts +0 -133
- package/dist/services/ResourceService.d.ts +0 -264
- package/dist/services/RevisionService.d.ts +0 -62
- package/dist/services/RoleMappingService.d.ts +0 -151
- package/dist/services/RoleService.d.ts +0 -276
- package/dist/services/RuleService.d.ts +0 -217
- package/dist/services/ScromSessionService.d.ts +0 -18
- package/dist/services/SettingService.d.ts +0 -147
- package/dist/services/ShiftService.d.ts +0 -181
- package/dist/services/ShiftTypeService.d.ts +0 -142
- package/dist/services/StationService.d.ts +0 -50
- package/dist/services/StockService.d.ts +0 -766
- package/dist/services/SyncClientsService.d.ts +0 -142
- package/dist/services/SyncHistoryService.d.ts +0 -142
- package/dist/services/SyncService.d.ts +0 -89
- package/dist/services/TableService.d.ts +0 -154
- package/dist/services/TableSetupService.d.ts +0 -40
- package/dist/services/TimeLogReportService.d.ts +0 -87
- package/dist/services/TimelineService.d.ts +0 -73
- package/dist/services/ToolService.d.ts +0 -73
- package/dist/services/TranslationService.d.ts +0 -172
- package/dist/services/UnitService.d.ts +0 -182
- package/dist/services/UpdateInfoService.d.ts +0 -24
- package/dist/services/UserModelService.d.ts +0 -245
- package/dist/services/VariantService.d.ts +0 -42
- package/dist/services/VoteMappingService.d.ts +0 -19
- package/dist/services/WarehouseService.d.ts +0 -19
- package/dist/services/WebhookService.d.ts +0 -58
- package/dist/services/WireService.d.ts +0 -151
- package/dist/services/WiringlistService.d.ts +0 -340
- package/dist/services/WorkflowDetailsService.d.ts +0 -151
- package/dist/services/WorkflowNoteService.d.ts +0 -173
- package/dist/services/WorkflowService.d.ts +0 -976
- package/dist/services/WorkflowSessionItemRecordService.d.ts +0 -19
- package/dist/services/WorkflowSessionItemService.d.ts +0 -205
- package/dist/services/WorkflowTypeService.d.ts +0 -49
- package/dist/services/WorkorderService.d.ts +0 -1138
- package/dist/services/WorkorderStatusService.d.ts +0 -78
- package/dist/services/WorkorderTemplateService.d.ts +0 -49
- package/tsconfig.build.json +0 -14
package/src/index.ts
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
import { createClient } from './sdk/client';
|
|
3
|
+
import { UserModelService } from './sdk';
|
|
4
|
+
import * as AllServices from './sdk';
|
|
5
|
+
|
|
6
|
+
const log = debug('nextplus:sdk');
|
|
7
|
+
|
|
8
|
+
const accessToken = {
|
|
9
|
+
token: null as string | null,
|
|
10
|
+
created: null as Date | null,
|
|
11
|
+
ttl: 0,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const setAccessToken = (token: string, created: Date = new Date(), ttl: number = 1209600) => {
|
|
15
|
+
accessToken.token = token;
|
|
16
|
+
accessToken.created = created;
|
|
17
|
+
accessToken.ttl = ttl;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const getAccessToken = () => {
|
|
21
|
+
return accessToken;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const isTokenValid = (): boolean => {
|
|
25
|
+
if (!accessToken.token || !accessToken.created) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const now = new Date();
|
|
30
|
+
const tokenAge = now.getTime() - accessToken.created.getTime();
|
|
31
|
+
const tokenTtlMs = accessToken.ttl * 1000; // TTL is in seconds
|
|
32
|
+
|
|
33
|
+
return tokenAge < tokenTtlMs;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class NextPlusSDK {
|
|
39
|
+
private client: any;
|
|
40
|
+
private credentials: { email?: string; username?: string; password: string };
|
|
41
|
+
private returnType: 'raw' | 'data' = 'data';
|
|
42
|
+
|
|
43
|
+
constructor(options: {
|
|
44
|
+
baseURL: string;
|
|
45
|
+
email?: string;
|
|
46
|
+
username?: string;
|
|
47
|
+
password: string;
|
|
48
|
+
returnType?: 'raw' | 'data';
|
|
49
|
+
}) {
|
|
50
|
+
// Validate that either email or username is provided
|
|
51
|
+
if (!options.email && !options.username) {
|
|
52
|
+
throw new Error('Either email or username must be provided');
|
|
53
|
+
}
|
|
54
|
+
if (options.email && options.username) {
|
|
55
|
+
throw new Error('Provide either email or username, not both');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.credentials = {
|
|
59
|
+
email: options.email,
|
|
60
|
+
username: options.username,
|
|
61
|
+
password: options.password
|
|
62
|
+
};
|
|
63
|
+
this.returnType = options.returnType || 'data';
|
|
64
|
+
// remove trailing slash from baseURL
|
|
65
|
+
if (options.baseURL.endsWith('/')) {
|
|
66
|
+
options.baseURL = options.baseURL.slice(0, -1);
|
|
67
|
+
}
|
|
68
|
+
// if baseURL does not end with /api, add it
|
|
69
|
+
if (!options.baseURL.endsWith('/api')) {
|
|
70
|
+
options.baseURL = options.baseURL + '/api';
|
|
71
|
+
}
|
|
72
|
+
this.client = createClient({
|
|
73
|
+
baseUrl: options.baseURL,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Add authentication interceptor
|
|
77
|
+
this.client.interceptors.request.use(this.authRequestInterceptor.bind(this));
|
|
78
|
+
|
|
79
|
+
// Create service proxies dynamically
|
|
80
|
+
this.createServiceProxies();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private async authRequestInterceptor(request: Request, _options: any) {
|
|
84
|
+
// Skip for UserModels/login
|
|
85
|
+
if (request.url.includes('/UserModels/login')) {
|
|
86
|
+
return request;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Ensure we have a valid token
|
|
90
|
+
await this.ensureValidToken();
|
|
91
|
+
|
|
92
|
+
const token = getAccessToken();
|
|
93
|
+
if (token.token) {
|
|
94
|
+
request.headers.set('Authorization', token.token);
|
|
95
|
+
}
|
|
96
|
+
return request;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private async ensureValidToken(): Promise<void> {
|
|
100
|
+
if (!isTokenValid()) {
|
|
101
|
+
log('Token expired or missing, refreshing...');
|
|
102
|
+
await this.login();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private async login(): Promise<boolean> {
|
|
107
|
+
try {
|
|
108
|
+
const loginBody: any = {
|
|
109
|
+
password: this.credentials.password,
|
|
110
|
+
forceLogin: true,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// Use email if provided, otherwise use username
|
|
114
|
+
if (this.credentials.email) {
|
|
115
|
+
loginBody.email = this.credentials.email;
|
|
116
|
+
} else if (this.credentials.username) {
|
|
117
|
+
loginBody.username = this.credentials.username;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const response = await UserModelService.login({
|
|
121
|
+
client: this.client,
|
|
122
|
+
body: loginBody,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (response.data) {
|
|
126
|
+
const token = (response.data as any).id;
|
|
127
|
+
const ttl = (response.data as any).ttl || 1209600;
|
|
128
|
+
if (token) {
|
|
129
|
+
setAccessToken(token, new Date(), ttl);
|
|
130
|
+
log('Login successful, access token set');
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
throw new Error('Login failed - no token received');
|
|
136
|
+
} catch (error) {
|
|
137
|
+
console.error('Login failed:', error);
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private createServiceProxies() {
|
|
143
|
+
// Get all service classes from the SDK
|
|
144
|
+
const serviceNames = Object.keys(AllServices).filter(key =>
|
|
145
|
+
key.endsWith('Service') && typeof (AllServices as any)[key] === 'function'
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
serviceNames.forEach(serviceName => {
|
|
149
|
+
const ServiceClass = (AllServices as any)[serviceName];
|
|
150
|
+
|
|
151
|
+
// Create a proxy for each service
|
|
152
|
+
(this as any)[serviceName] = this.createServiceProxy(ServiceClass);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private createServiceProxy(ServiceClass: any) {
|
|
157
|
+
const self = this;
|
|
158
|
+
return new Proxy(ServiceClass, {
|
|
159
|
+
get(target, prop) {
|
|
160
|
+
if (typeof target[prop] === 'function') {
|
|
161
|
+
return async function(...args: any[]) {
|
|
162
|
+
// Automatically inject client if not provided
|
|
163
|
+
if (args[0] && typeof args[0] === 'object' && !args[0].client) {
|
|
164
|
+
args[0].client = self.client;
|
|
165
|
+
} else if (!args[0]) {
|
|
166
|
+
args[0] = { client: self.client };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const result = await target[prop].apply(target, args);
|
|
170
|
+
|
|
171
|
+
// Return based on returnType setting
|
|
172
|
+
if (self.returnType === 'data' && result && typeof result === 'object' && 'data' in result) {
|
|
173
|
+
return result.data;
|
|
174
|
+
}
|
|
175
|
+
if (self.returnType === 'data' && result && typeof result === 'object' && 'error' in result) {
|
|
176
|
+
const error = new Error(result.error.error.message || result.error.error.code || 'Unknown error') as any;
|
|
177
|
+
if (result.error.error.details) {
|
|
178
|
+
error.details = result.error.error.details;
|
|
179
|
+
}
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
// Return raw response (default behavior)
|
|
183
|
+
return result;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return target[prop];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Manual login method (optional, for explicit control)
|
|
192
|
+
async manualLogin(): Promise<boolean> {
|
|
193
|
+
return this.login();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Legacy function for backward compatibility
|
|
198
|
+
const configure = (options: {
|
|
199
|
+
baseURL: string;
|
|
200
|
+
email?: string;
|
|
201
|
+
username?: string;
|
|
202
|
+
password: string;
|
|
203
|
+
returnType?: 'raw' | 'data';
|
|
204
|
+
}) => {
|
|
205
|
+
return new NextPlusSDK(options);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// Create SDK instance
|
|
209
|
+
const createSDK = (options: {
|
|
210
|
+
baseURL: string;
|
|
211
|
+
email?: string;
|
|
212
|
+
username?: string;
|
|
213
|
+
password: string;
|
|
214
|
+
returnType?: 'raw' | 'data';
|
|
215
|
+
}) => {
|
|
216
|
+
return new NextPlusSDK(options);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export { configure, createSDK, NextPlusSDK };
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import type { Client, Config, ResolvedRequestOptions } from './types.gen';
|
|
4
|
+
import {
|
|
5
|
+
buildUrl,
|
|
6
|
+
createConfig,
|
|
7
|
+
createInterceptors,
|
|
8
|
+
getParseAs,
|
|
9
|
+
mergeConfigs,
|
|
10
|
+
mergeHeaders,
|
|
11
|
+
setAuthParams,
|
|
12
|
+
} from './utils.gen';
|
|
13
|
+
|
|
14
|
+
type ReqInit = Omit<RequestInit, 'body' | 'headers'> & {
|
|
15
|
+
body?: any;
|
|
16
|
+
headers: ReturnType<typeof mergeHeaders>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const createClient = (config: Config = {}): Client => {
|
|
20
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
21
|
+
|
|
22
|
+
const getConfig = (): Config => ({ ..._config });
|
|
23
|
+
|
|
24
|
+
const setConfig = (config: Config): Config => {
|
|
25
|
+
_config = mergeConfigs(_config, config);
|
|
26
|
+
return getConfig();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const interceptors = createInterceptors<
|
|
30
|
+
Request,
|
|
31
|
+
Response,
|
|
32
|
+
unknown,
|
|
33
|
+
ResolvedRequestOptions
|
|
34
|
+
>();
|
|
35
|
+
|
|
36
|
+
const request: Client['request'] = async (options) => {
|
|
37
|
+
const opts = {
|
|
38
|
+
..._config,
|
|
39
|
+
...options,
|
|
40
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
41
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
42
|
+
serializedBody: undefined,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
if (opts.security) {
|
|
46
|
+
await setAuthParams({
|
|
47
|
+
...opts,
|
|
48
|
+
security: opts.security,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (opts.requestValidator) {
|
|
53
|
+
await opts.requestValidator(opts);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (opts.body && opts.bodySerializer) {
|
|
57
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
61
|
+
if (opts.serializedBody === undefined || opts.serializedBody === '') {
|
|
62
|
+
opts.headers.delete('Content-Type');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const url = buildUrl(opts);
|
|
66
|
+
const requestInit: ReqInit = {
|
|
67
|
+
redirect: 'follow',
|
|
68
|
+
...opts,
|
|
69
|
+
body: opts.serializedBody,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
let request = new Request(url, requestInit);
|
|
73
|
+
|
|
74
|
+
for (const fn of interceptors.request._fns) {
|
|
75
|
+
if (fn) {
|
|
76
|
+
request = await fn(request, opts);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
81
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
82
|
+
const _fetch = opts.fetch!;
|
|
83
|
+
let response = await _fetch(request);
|
|
84
|
+
|
|
85
|
+
for (const fn of interceptors.response._fns) {
|
|
86
|
+
if (fn) {
|
|
87
|
+
response = await fn(response, request, opts);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const result = {
|
|
92
|
+
request,
|
|
93
|
+
response,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
if (response.ok) {
|
|
97
|
+
if (
|
|
98
|
+
response.status === 204 ||
|
|
99
|
+
response.headers.get('Content-Length') === '0'
|
|
100
|
+
) {
|
|
101
|
+
return opts.responseStyle === 'data'
|
|
102
|
+
? {}
|
|
103
|
+
: {
|
|
104
|
+
data: {},
|
|
105
|
+
...result,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const parseAs =
|
|
110
|
+
(opts.parseAs === 'auto'
|
|
111
|
+
? getParseAs(response.headers.get('Content-Type'))
|
|
112
|
+
: opts.parseAs) ?? 'json';
|
|
113
|
+
|
|
114
|
+
let data: any;
|
|
115
|
+
switch (parseAs) {
|
|
116
|
+
case 'arrayBuffer':
|
|
117
|
+
case 'blob':
|
|
118
|
+
case 'formData':
|
|
119
|
+
case 'json':
|
|
120
|
+
case 'text':
|
|
121
|
+
data = await response[parseAs]();
|
|
122
|
+
break;
|
|
123
|
+
case 'stream':
|
|
124
|
+
return opts.responseStyle === 'data'
|
|
125
|
+
? response.body
|
|
126
|
+
: {
|
|
127
|
+
data: response.body,
|
|
128
|
+
...result,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (parseAs === 'json') {
|
|
133
|
+
if (opts.responseValidator) {
|
|
134
|
+
await opts.responseValidator(data);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (opts.responseTransformer) {
|
|
138
|
+
data = await opts.responseTransformer(data);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return opts.responseStyle === 'data'
|
|
143
|
+
? data
|
|
144
|
+
: {
|
|
145
|
+
data,
|
|
146
|
+
...result,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const textError = await response.text();
|
|
151
|
+
let jsonError: unknown;
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
jsonError = JSON.parse(textError);
|
|
155
|
+
} catch {
|
|
156
|
+
// noop
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const error = jsonError ?? textError;
|
|
160
|
+
let finalError = error;
|
|
161
|
+
|
|
162
|
+
for (const fn of interceptors.error._fns) {
|
|
163
|
+
if (fn) {
|
|
164
|
+
finalError = (await fn(error, response, request, opts)) as string;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
finalError = finalError || ({} as string);
|
|
169
|
+
|
|
170
|
+
if (opts.throwOnError) {
|
|
171
|
+
throw finalError;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// TODO: we probably want to return error and improve types
|
|
175
|
+
return opts.responseStyle === 'data'
|
|
176
|
+
? undefined
|
|
177
|
+
: {
|
|
178
|
+
error: finalError,
|
|
179
|
+
...result,
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
buildUrl,
|
|
185
|
+
connect: (options) => request({ ...options, method: 'CONNECT' }),
|
|
186
|
+
delete: (options) => request({ ...options, method: 'DELETE' }),
|
|
187
|
+
get: (options) => request({ ...options, method: 'GET' }),
|
|
188
|
+
getConfig,
|
|
189
|
+
head: (options) => request({ ...options, method: 'HEAD' }),
|
|
190
|
+
interceptors,
|
|
191
|
+
options: (options) => request({ ...options, method: 'OPTIONS' }),
|
|
192
|
+
patch: (options) => request({ ...options, method: 'PATCH' }),
|
|
193
|
+
post: (options) => request({ ...options, method: 'POST' }),
|
|
194
|
+
put: (options) => request({ ...options, method: 'PUT' }),
|
|
195
|
+
request,
|
|
196
|
+
setConfig,
|
|
197
|
+
trace: (options) => request({ ...options, method: 'TRACE' }),
|
|
198
|
+
};
|
|
199
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
export type { Auth } from '../core/auth.gen';
|
|
4
|
+
export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
5
|
+
export {
|
|
6
|
+
formDataBodySerializer,
|
|
7
|
+
jsonBodySerializer,
|
|
8
|
+
urlSearchParamsBodySerializer,
|
|
9
|
+
} from '../core/bodySerializer.gen';
|
|
10
|
+
export { buildClientParams } from '../core/params.gen';
|
|
11
|
+
export { createClient } from './client.gen';
|
|
12
|
+
export type {
|
|
13
|
+
Client,
|
|
14
|
+
ClientOptions,
|
|
15
|
+
Config,
|
|
16
|
+
CreateClientConfig,
|
|
17
|
+
Options,
|
|
18
|
+
OptionsLegacyParser,
|
|
19
|
+
RequestOptions,
|
|
20
|
+
RequestResult,
|
|
21
|
+
ResolvedRequestOptions,
|
|
22
|
+
ResponseStyle,
|
|
23
|
+
TDataShape,
|
|
24
|
+
} from './types.gen';
|
|
25
|
+
export { createConfig, mergeHeaders } from './utils.gen';
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import type { Auth } from '../core/auth.gen';
|
|
4
|
+
import type {
|
|
5
|
+
Client as CoreClient,
|
|
6
|
+
Config as CoreConfig,
|
|
7
|
+
} from '../core/types.gen';
|
|
8
|
+
import type { Middleware } from './utils.gen';
|
|
9
|
+
|
|
10
|
+
export type ResponseStyle = 'data' | 'fields';
|
|
11
|
+
|
|
12
|
+
export interface Config<T extends ClientOptions = ClientOptions>
|
|
13
|
+
extends Omit<RequestInit, 'body' | 'headers' | 'method'>,
|
|
14
|
+
CoreConfig {
|
|
15
|
+
/**
|
|
16
|
+
* Base URL for all requests made by this client.
|
|
17
|
+
*/
|
|
18
|
+
baseUrl?: T['baseUrl'];
|
|
19
|
+
/**
|
|
20
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
21
|
+
* fetch instance.
|
|
22
|
+
*
|
|
23
|
+
* @default globalThis.fetch
|
|
24
|
+
*/
|
|
25
|
+
fetch?: (request: Request) => ReturnType<typeof fetch>;
|
|
26
|
+
/**
|
|
27
|
+
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
28
|
+
* options won't have any effect.
|
|
29
|
+
*
|
|
30
|
+
* Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
|
|
31
|
+
*/
|
|
32
|
+
next?: never;
|
|
33
|
+
/**
|
|
34
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
35
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
36
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
37
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
38
|
+
*
|
|
39
|
+
* @default 'auto'
|
|
40
|
+
*/
|
|
41
|
+
parseAs?:
|
|
42
|
+
| 'arrayBuffer'
|
|
43
|
+
| 'auto'
|
|
44
|
+
| 'blob'
|
|
45
|
+
| 'formData'
|
|
46
|
+
| 'json'
|
|
47
|
+
| 'stream'
|
|
48
|
+
| 'text';
|
|
49
|
+
/**
|
|
50
|
+
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
51
|
+
*
|
|
52
|
+
* @default 'fields'
|
|
53
|
+
*/
|
|
54
|
+
responseStyle?: ResponseStyle;
|
|
55
|
+
/**
|
|
56
|
+
* Throw an error instead of returning it in the response?
|
|
57
|
+
*
|
|
58
|
+
* @default false
|
|
59
|
+
*/
|
|
60
|
+
throwOnError?: T['throwOnError'];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface RequestOptions<
|
|
64
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
65
|
+
ThrowOnError extends boolean = boolean,
|
|
66
|
+
Url extends string = string,
|
|
67
|
+
> extends Config<{
|
|
68
|
+
responseStyle: TResponseStyle;
|
|
69
|
+
throwOnError: ThrowOnError;
|
|
70
|
+
}> {
|
|
71
|
+
/**
|
|
72
|
+
* Any body that you want to add to your request.
|
|
73
|
+
*
|
|
74
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
75
|
+
*/
|
|
76
|
+
body?: unknown;
|
|
77
|
+
path?: Record<string, unknown>;
|
|
78
|
+
query?: Record<string, unknown>;
|
|
79
|
+
/**
|
|
80
|
+
* Security mechanism(s) to use for the request.
|
|
81
|
+
*/
|
|
82
|
+
security?: ReadonlyArray<Auth>;
|
|
83
|
+
url: Url;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface ResolvedRequestOptions<
|
|
87
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
88
|
+
ThrowOnError extends boolean = boolean,
|
|
89
|
+
Url extends string = string,
|
|
90
|
+
> extends RequestOptions<TResponseStyle, ThrowOnError, Url> {
|
|
91
|
+
serializedBody?: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export type RequestResult<
|
|
95
|
+
TData = unknown,
|
|
96
|
+
TError = unknown,
|
|
97
|
+
ThrowOnError extends boolean = boolean,
|
|
98
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
99
|
+
> = ThrowOnError extends true
|
|
100
|
+
? Promise<
|
|
101
|
+
TResponseStyle extends 'data'
|
|
102
|
+
? TData extends Record<string, unknown>
|
|
103
|
+
? TData[keyof TData]
|
|
104
|
+
: TData
|
|
105
|
+
: {
|
|
106
|
+
data: TData extends Record<string, unknown>
|
|
107
|
+
? TData[keyof TData]
|
|
108
|
+
: TData;
|
|
109
|
+
request: Request;
|
|
110
|
+
response: Response;
|
|
111
|
+
}
|
|
112
|
+
>
|
|
113
|
+
: Promise<
|
|
114
|
+
TResponseStyle extends 'data'
|
|
115
|
+
?
|
|
116
|
+
| (TData extends Record<string, unknown>
|
|
117
|
+
? TData[keyof TData]
|
|
118
|
+
: TData)
|
|
119
|
+
| undefined
|
|
120
|
+
: (
|
|
121
|
+
| {
|
|
122
|
+
data: TData extends Record<string, unknown>
|
|
123
|
+
? TData[keyof TData]
|
|
124
|
+
: TData;
|
|
125
|
+
error: undefined;
|
|
126
|
+
}
|
|
127
|
+
| {
|
|
128
|
+
data: undefined;
|
|
129
|
+
error: TError extends Record<string, unknown>
|
|
130
|
+
? TError[keyof TError]
|
|
131
|
+
: TError;
|
|
132
|
+
}
|
|
133
|
+
) & {
|
|
134
|
+
request: Request;
|
|
135
|
+
response: Response;
|
|
136
|
+
}
|
|
137
|
+
>;
|
|
138
|
+
|
|
139
|
+
export interface ClientOptions {
|
|
140
|
+
baseUrl?: string;
|
|
141
|
+
responseStyle?: ResponseStyle;
|
|
142
|
+
throwOnError?: boolean;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
type MethodFn = <
|
|
146
|
+
TData = unknown,
|
|
147
|
+
TError = unknown,
|
|
148
|
+
ThrowOnError extends boolean = false,
|
|
149
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
150
|
+
>(
|
|
151
|
+
options: Omit<RequestOptions<TResponseStyle, ThrowOnError>, 'method'>,
|
|
152
|
+
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
153
|
+
|
|
154
|
+
type RequestFn = <
|
|
155
|
+
TData = unknown,
|
|
156
|
+
TError = unknown,
|
|
157
|
+
ThrowOnError extends boolean = false,
|
|
158
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
159
|
+
>(
|
|
160
|
+
options: Omit<RequestOptions<TResponseStyle, ThrowOnError>, 'method'> &
|
|
161
|
+
Pick<Required<RequestOptions<TResponseStyle, ThrowOnError>>, 'method'>,
|
|
162
|
+
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
163
|
+
|
|
164
|
+
type BuildUrlFn = <
|
|
165
|
+
TData extends {
|
|
166
|
+
body?: unknown;
|
|
167
|
+
path?: Record<string, unknown>;
|
|
168
|
+
query?: Record<string, unknown>;
|
|
169
|
+
url: string;
|
|
170
|
+
},
|
|
171
|
+
>(
|
|
172
|
+
options: Pick<TData, 'url'> & Options<TData>,
|
|
173
|
+
) => string;
|
|
174
|
+
|
|
175
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn> & {
|
|
176
|
+
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
181
|
+
* and the returned object will become the client's initial configuration.
|
|
182
|
+
*
|
|
183
|
+
* You may want to initialize your client this way instead of calling
|
|
184
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
185
|
+
* to ensure your client always has the correct values.
|
|
186
|
+
*/
|
|
187
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (
|
|
188
|
+
override?: Config<ClientOptions & T>,
|
|
189
|
+
) => Config<Required<ClientOptions> & T>;
|
|
190
|
+
|
|
191
|
+
export interface TDataShape {
|
|
192
|
+
body?: unknown;
|
|
193
|
+
headers?: unknown;
|
|
194
|
+
path?: unknown;
|
|
195
|
+
query?: unknown;
|
|
196
|
+
url: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
200
|
+
|
|
201
|
+
export type Options<
|
|
202
|
+
TData extends TDataShape = TDataShape,
|
|
203
|
+
ThrowOnError extends boolean = boolean,
|
|
204
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
205
|
+
> = OmitKeys<
|
|
206
|
+
RequestOptions<TResponseStyle, ThrowOnError>,
|
|
207
|
+
'body' | 'path' | 'query' | 'url'
|
|
208
|
+
> &
|
|
209
|
+
Omit<TData, 'url'>;
|
|
210
|
+
|
|
211
|
+
export type OptionsLegacyParser<
|
|
212
|
+
TData = unknown,
|
|
213
|
+
ThrowOnError extends boolean = boolean,
|
|
214
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
215
|
+
> = TData extends { body?: any }
|
|
216
|
+
? TData extends { headers?: any }
|
|
217
|
+
? OmitKeys<
|
|
218
|
+
RequestOptions<TResponseStyle, ThrowOnError>,
|
|
219
|
+
'body' | 'headers' | 'url'
|
|
220
|
+
> &
|
|
221
|
+
TData
|
|
222
|
+
: OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'body' | 'url'> &
|
|
223
|
+
TData &
|
|
224
|
+
Pick<RequestOptions<TResponseStyle, ThrowOnError>, 'headers'>
|
|
225
|
+
: TData extends { headers?: any }
|
|
226
|
+
? OmitKeys<
|
|
227
|
+
RequestOptions<TResponseStyle, ThrowOnError>,
|
|
228
|
+
'headers' | 'url'
|
|
229
|
+
> &
|
|
230
|
+
TData &
|
|
231
|
+
Pick<RequestOptions<TResponseStyle, ThrowOnError>, 'body'>
|
|
232
|
+
: OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'url'> & TData;
|