@nextplus/js-sdk 0.0.4 → 0.0.6

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.
@@ -0,0 +1,45 @@
1
+ import { A as AllServiceTypes } from './index-DnDzRLml.cjs';
2
+ import './sdk.gen-CPR3KdM-.cjs';
3
+ import './types.gen-vDP9AbtO.cjs';
4
+
5
+ type ServiceStatics = {
6
+ [K in keyof typeof AllServiceTypes as K extends `${string}Service` ? K : never]: typeof AllServiceTypes[K];
7
+ };
8
+ declare class NextPlusSDK {
9
+ private client;
10
+ private credentials;
11
+ private returnType;
12
+ private normalizeOptions;
13
+ constructor(options: {
14
+ baseURL: string;
15
+ email?: string;
16
+ username?: string;
17
+ password: string;
18
+ returnType?: 'raw' | 'data';
19
+ });
20
+ private authRequestInterceptor;
21
+ private ensureValidToken;
22
+ private login;
23
+ private createServiceProxies;
24
+ private createServiceProxy;
25
+ manualLogin(): Promise<boolean>;
26
+ }
27
+ interface NextPlusSDK extends ServiceStatics {
28
+ }
29
+ type SDKInstance = NextPlusSDK & ServiceStatics;
30
+ declare const configure: (options: {
31
+ baseURL: string;
32
+ email?: string;
33
+ username?: string;
34
+ password: string;
35
+ returnType?: "raw" | "data";
36
+ }) => SDKInstance;
37
+ declare const createSDK: (options: {
38
+ baseURL: string;
39
+ email?: string;
40
+ username?: string;
41
+ password: string;
42
+ returnType?: "raw" | "data";
43
+ }) => SDKInstance;
44
+
45
+ export { NextPlusSDK, type SDKInstance, configure, createSDK };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,15 @@
1
+ import { A as AllServiceTypes } from './index-_9HQhd2P.js';
2
+ import './sdk.gen-D3Q8YKqz.js';
3
+ import './types.gen-vDP9AbtO.js';
4
+
5
+ type ServiceStatics = {
6
+ [K in keyof typeof AllServiceTypes as K extends `${string}Service` ? K : never]: typeof AllServiceTypes[K];
7
+ };
1
8
  declare class NextPlusSDK {
2
9
  private client;
3
10
  private credentials;
4
11
  private returnType;
12
+ private normalizeOptions;
5
13
  constructor(options: {
6
14
  baseURL: string;
7
15
  email?: string;
@@ -16,19 +24,22 @@ declare class NextPlusSDK {
16
24
  private createServiceProxy;
17
25
  manualLogin(): Promise<boolean>;
18
26
  }
27
+ interface NextPlusSDK extends ServiceStatics {
28
+ }
29
+ type SDKInstance = NextPlusSDK & ServiceStatics;
19
30
  declare const configure: (options: {
20
31
  baseURL: string;
21
32
  email?: string;
22
33
  username?: string;
23
34
  password: string;
24
35
  returnType?: "raw" | "data";
25
- }) => NextPlusSDK;
36
+ }) => SDKInstance;
26
37
  declare const createSDK: (options: {
27
38
  baseURL: string;
28
39
  email?: string;
29
40
  username?: string;
30
41
  password: string;
31
42
  returnType?: "raw" | "data";
32
- }) => NextPlusSDK;
43
+ }) => SDKInstance;
33
44
 
34
- export { NextPlusSDK, configure, createSDK };
45
+ export { NextPlusSDK, type SDKInstance, configure, createSDK };
package/dist/index.js CHANGED
@@ -1,228 +1,16 @@
1
1
  import {
2
- AclService,
3
- AiPromptService,
4
- AiService,
5
- ApiMethodLogService,
6
- ApiMethodService,
7
- BomService,
8
- BreakService,
9
- BreakTypeService,
10
- CatalogService,
11
- CategoryService,
12
- CertificateMappingService,
13
- CertificateService,
14
- ChapterService,
15
- CommentService,
16
- ConfigurationService,
17
- ConnectionService,
18
- ConnectorFunctionService,
19
- ConnectorService,
20
- ContainerService,
21
- ContentPackageService,
22
- ContentPackageSessionService,
23
- ContentPackageViewService,
24
- CustomFieldService,
25
- DeviceFamilyService,
26
- DeviceService,
27
- DigestEmailService,
28
- DocumentService,
29
- EventService,
30
- FieldService,
31
- FileParserJobService,
32
- FileParserService,
33
- FileParserStrategyJobService,
34
- FolderService,
35
- FormDataCommentService,
36
- FormDataService,
37
- FormService,
38
- ForumService,
39
- GatewayService,
40
- GroupService,
41
- IntegrationBuilderService,
42
- InventoryTransactionService,
43
- LastSeenResourceService,
44
- ListItemService,
45
- ListService,
46
- LocationService,
47
- MenusService,
48
- NodeService,
49
- NpsService,
50
- OpcUaServerService,
51
- OperationService,
52
- PagesService,
53
- PartAssemblyDocumentService,
54
- PartAssemblyService,
55
- PartService,
56
- PostService,
57
- PrintPresetService,
58
- PriorityLabelService,
59
- PriorityService,
60
- ProductionEntityEventService,
61
- ProductionEntityMappingService,
62
- ProductionEntityService,
63
- ProductionEntityTransactionService,
64
- ProductionEntityTypeService,
65
- ProjectService,
66
- PythonResultService,
67
- ResourceMappingService,
68
- ResourceService,
69
- RevisionService,
70
- RoleMappingService,
71
- RoleService,
72
- RuleService,
73
- ScromSessionService,
74
- SettingService,
75
- ShiftService,
76
- ShiftTypeService,
77
- StationService,
78
- StockService,
79
- SyncClientsService,
80
- SyncHistoryService,
81
- SyncService,
82
- TableService,
83
- TableSetupService,
84
- TimeLogReportService,
85
- TimelineService,
86
- ToolService,
87
- TranslationService,
88
- UnitService,
89
- UpdateInfoService,
90
- UserModelService,
91
- VariantService,
92
- VoteMappingService,
93
- WarehouseService,
94
- WebhookService,
95
- WireService,
96
- WiringlistService,
97
- WorkflowDetailsService,
98
- WorkflowNoteService,
99
- WorkflowService,
100
- WorkflowSessionItemRecordService,
101
- WorkflowSessionItemService,
102
- WorkflowTypeService,
103
- WorkorderService,
104
- WorkorderStatusService,
105
- WorkorderTemplateService
2
+ sdk_exports
3
+ } from "./chunk-YEF23TVP.js";
4
+ import {
5
+ UserModelService
106
6
  } from "./chunk-DNVJS7WW.js";
107
7
  import {
108
- __export,
109
8
  __publicField,
110
9
  createClient
111
10
  } from "./chunk-FXXZNC42.js";
112
11
 
113
12
  // src/index.ts
114
13
  import debug from "debug";
115
-
116
- // src/sdk/index.ts
117
- var sdk_exports = {};
118
- __export(sdk_exports, {
119
- AclService: () => AclService,
120
- AiPromptService: () => AiPromptService,
121
- AiService: () => AiService,
122
- ApiMethodLogService: () => ApiMethodLogService,
123
- ApiMethodService: () => ApiMethodService,
124
- BomService: () => BomService,
125
- BreakService: () => BreakService,
126
- BreakTypeService: () => BreakTypeService,
127
- CatalogService: () => CatalogService,
128
- CategoryService: () => CategoryService,
129
- CertificateMappingService: () => CertificateMappingService,
130
- CertificateService: () => CertificateService,
131
- ChapterService: () => ChapterService,
132
- CommentService: () => CommentService,
133
- ConfigurationService: () => ConfigurationService,
134
- ConnectionService: () => ConnectionService,
135
- ConnectorFunctionService: () => ConnectorFunctionService,
136
- ConnectorService: () => ConnectorService,
137
- ContainerService: () => ContainerService,
138
- ContentPackageService: () => ContentPackageService,
139
- ContentPackageSessionService: () => ContentPackageSessionService,
140
- ContentPackageViewService: () => ContentPackageViewService,
141
- CustomFieldService: () => CustomFieldService,
142
- DeviceFamilyService: () => DeviceFamilyService,
143
- DeviceService: () => DeviceService,
144
- DigestEmailService: () => DigestEmailService,
145
- DocumentService: () => DocumentService,
146
- EventService: () => EventService,
147
- FieldService: () => FieldService,
148
- FileParserJobService: () => FileParserJobService,
149
- FileParserService: () => FileParserService,
150
- FileParserStrategyJobService: () => FileParserStrategyJobService,
151
- FolderService: () => FolderService,
152
- FormDataCommentService: () => FormDataCommentService,
153
- FormDataService: () => FormDataService,
154
- FormService: () => FormService,
155
- ForumService: () => ForumService,
156
- GatewayService: () => GatewayService,
157
- GroupService: () => GroupService,
158
- IntegrationBuilderService: () => IntegrationBuilderService,
159
- InventoryTransactionService: () => InventoryTransactionService,
160
- LastSeenResourceService: () => LastSeenResourceService,
161
- ListItemService: () => ListItemService,
162
- ListService: () => ListService,
163
- LocationService: () => LocationService,
164
- MenusService: () => MenusService,
165
- NodeService: () => NodeService,
166
- NpsService: () => NpsService,
167
- OpcUaServerService: () => OpcUaServerService,
168
- OperationService: () => OperationService,
169
- PagesService: () => PagesService,
170
- PartAssemblyDocumentService: () => PartAssemblyDocumentService,
171
- PartAssemblyService: () => PartAssemblyService,
172
- PartService: () => PartService,
173
- PostService: () => PostService,
174
- PrintPresetService: () => PrintPresetService,
175
- PriorityLabelService: () => PriorityLabelService,
176
- PriorityService: () => PriorityService,
177
- ProductionEntityEventService: () => ProductionEntityEventService,
178
- ProductionEntityMappingService: () => ProductionEntityMappingService,
179
- ProductionEntityService: () => ProductionEntityService,
180
- ProductionEntityTransactionService: () => ProductionEntityTransactionService,
181
- ProductionEntityTypeService: () => ProductionEntityTypeService,
182
- ProjectService: () => ProjectService,
183
- PythonResultService: () => PythonResultService,
184
- ResourceMappingService: () => ResourceMappingService,
185
- ResourceService: () => ResourceService,
186
- RevisionService: () => RevisionService,
187
- RoleMappingService: () => RoleMappingService,
188
- RoleService: () => RoleService,
189
- RuleService: () => RuleService,
190
- ScromSessionService: () => ScromSessionService,
191
- SettingService: () => SettingService,
192
- ShiftService: () => ShiftService,
193
- ShiftTypeService: () => ShiftTypeService,
194
- StationService: () => StationService,
195
- StockService: () => StockService,
196
- SyncClientsService: () => SyncClientsService,
197
- SyncHistoryService: () => SyncHistoryService,
198
- SyncService: () => SyncService,
199
- TableService: () => TableService,
200
- TableSetupService: () => TableSetupService,
201
- TimeLogReportService: () => TimeLogReportService,
202
- TimelineService: () => TimelineService,
203
- ToolService: () => ToolService,
204
- TranslationService: () => TranslationService,
205
- UnitService: () => UnitService,
206
- UpdateInfoService: () => UpdateInfoService,
207
- UserModelService: () => UserModelService,
208
- VariantService: () => VariantService,
209
- VoteMappingService: () => VoteMappingService,
210
- WarehouseService: () => WarehouseService,
211
- WebhookService: () => WebhookService,
212
- WireService: () => WireService,
213
- WiringlistService: () => WiringlistService,
214
- WorkflowDetailsService: () => WorkflowDetailsService,
215
- WorkflowNoteService: () => WorkflowNoteService,
216
- WorkflowService: () => WorkflowService,
217
- WorkflowSessionItemRecordService: () => WorkflowSessionItemRecordService,
218
- WorkflowSessionItemService: () => WorkflowSessionItemService,
219
- WorkflowTypeService: () => WorkflowTypeService,
220
- WorkorderService: () => WorkorderService,
221
- WorkorderStatusService: () => WorkorderStatusService,
222
- WorkorderTemplateService: () => WorkorderTemplateService
223
- });
224
-
225
- // src/index.ts
226
14
  var log = debug("nextplus:sdk");
227
15
  var accessToken = {
228
16
  token: null,
@@ -275,6 +63,65 @@ var NextPlusSDK = class {
275
63
  this.client.interceptors.request.use(this.authRequestInterceptor.bind(this));
276
64
  this.createServiceProxies();
277
65
  }
66
+ // Wrap plain developer inputs into the right container (body/query)
67
+ // and stringify complex query params when required by LoopBack (filter/where)
68
+ normalizeOptions(methodName, rawOptions) {
69
+ const options = rawOptions && typeof rawOptions === "object" ? { ...rawOptions } : {};
70
+ const method = methodName.toString().toLowerCase();
71
+ const isFind = method.includes("find") && !method.includes("count");
72
+ const isCount = method.includes("count");
73
+ const shouldUseBody = /(create|update|replace|patch|login|upsert)/i.test(methodName.toString());
74
+ const topLevelKeys = ["filter", "where", "fields", "order", "limit", "offset", "include"];
75
+ const hasTopLevelFilterBits = topLevelKeys.some((k) => Object.prototype.hasOwnProperty.call(options, k));
76
+ if (isFind) {
77
+ options.query = options.query || {};
78
+ if (options.filter && typeof options.filter === "object") {
79
+ options.query.filter = JSON.stringify(options.filter);
80
+ delete options.filter;
81
+ } else if (hasTopLevelFilterBits) {
82
+ const filterObject = {};
83
+ if (options.where !== void 0) filterObject.where = options.where;
84
+ if (options.fields !== void 0) filterObject.fields = options.fields;
85
+ if (options.order !== void 0) filterObject.order = options.order;
86
+ if (options.limit !== void 0) filterObject.limit = options.limit;
87
+ if (options.offset !== void 0) filterObject.offset = options.offset;
88
+ if (options.include !== void 0) filterObject.include = options.include;
89
+ if (Object.keys(filterObject).length > 0) {
90
+ options.query.filter = typeof filterObject === "string" ? filterObject : JSON.stringify(filterObject);
91
+ }
92
+ topLevelKeys.forEach((k) => delete options[k]);
93
+ }
94
+ } else if (isCount) {
95
+ options.query = options.query || {};
96
+ if (options.where !== void 0) {
97
+ const whereVal = options.where;
98
+ options.query.where = typeof whereVal === "string" ? whereVal : JSON.stringify(whereVal);
99
+ delete options.where;
100
+ }
101
+ } else if (shouldUseBody) {
102
+ if (options.body === void 0) {
103
+ const bodyCandidate = { ...options };
104
+ delete bodyCandidate.client;
105
+ delete bodyCandidate.query;
106
+ delete bodyCandidate.path;
107
+ if (Object.keys(bodyCandidate).length > 0) {
108
+ options.body = bodyCandidate;
109
+ Object.keys(options).forEach((k) => {
110
+ if (!["body", "client", "query", "path"].includes(k)) delete options[k];
111
+ });
112
+ }
113
+ }
114
+ }
115
+ if (options.query && typeof options.query === "object") {
116
+ Object.keys(options.query).forEach((key) => {
117
+ const val = options.query[key];
118
+ if (val && (Array.isArray(val) || typeof val === "object")) {
119
+ options.query[key] = JSON.stringify(val);
120
+ }
121
+ });
122
+ }
123
+ return options;
124
+ }
278
125
  async authRequestInterceptor(request, _options) {
279
126
  if (request.url.includes("/UserModels/login")) {
280
127
  return request;
@@ -337,11 +184,9 @@ var NextPlusSDK = class {
337
184
  get(target, prop) {
338
185
  if (typeof target[prop] === "function") {
339
186
  return async function(...args) {
340
- if (args[0] && typeof args[0] === "object" && !args[0].client) {
341
- args[0].client = self.client;
342
- } else if (!args[0]) {
343
- args[0] = { client: self.client };
344
- }
187
+ if (!args[0]) args[0] = {};
188
+ args[0] = self.normalizeOptions(String(prop), args[0]);
189
+ if (!args[0].client) args[0].client = self.client;
345
190
  const result = await target[prop].apply(target, args);
346
191
  if (self.returnType === "data" && result && typeof result === "object" && "data" in result) {
347
192
  return result.data;