@ctil/gql 1.0.11 → 1.0.13
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/index.cjs +24 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +82 -1
- package/dist/index.d.ts +82 -1
- package/dist/index.js +22 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -59,6 +59,32 @@ interface UserToken {
|
|
|
59
59
|
/** 用户权限编码列表 */
|
|
60
60
|
permissions: string[];
|
|
61
61
|
}
|
|
62
|
+
interface rateLimitConfig$1 {
|
|
63
|
+
defaultRules: {
|
|
64
|
+
query: {
|
|
65
|
+
max: number;
|
|
66
|
+
window: number;
|
|
67
|
+
debounce: number;
|
|
68
|
+
};
|
|
69
|
+
mutation: {
|
|
70
|
+
max: number;
|
|
71
|
+
window: number;
|
|
72
|
+
debounce: number;
|
|
73
|
+
};
|
|
74
|
+
[key: string]: {
|
|
75
|
+
max: number;
|
|
76
|
+
window: number;
|
|
77
|
+
debounce: number;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
custom: {
|
|
81
|
+
[key: string]: {
|
|
82
|
+
max: number;
|
|
83
|
+
window: number;
|
|
84
|
+
debounce: number;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
}
|
|
62
88
|
|
|
63
89
|
declare class CCRequest {
|
|
64
90
|
private config;
|
|
@@ -142,6 +168,61 @@ declare function generateOperationName(entityName: string, original: string): st
|
|
|
142
168
|
declare function toPascalCase(str: string): string;
|
|
143
169
|
declare function buildCommonResultSelection(dataFields?: FieldInput[]): string;
|
|
144
170
|
|
|
171
|
+
declare const rateLimitConfig: {
|
|
172
|
+
defaultRules: {
|
|
173
|
+
query: {
|
|
174
|
+
max: number;
|
|
175
|
+
window: number;
|
|
176
|
+
debounce: number;
|
|
177
|
+
};
|
|
178
|
+
mutation: {
|
|
179
|
+
max: number;
|
|
180
|
+
window: number;
|
|
181
|
+
debounce: number;
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
custom: {
|
|
185
|
+
login: {
|
|
186
|
+
max: number;
|
|
187
|
+
window: number;
|
|
188
|
+
debounce: number;
|
|
189
|
+
};
|
|
190
|
+
refreshToken: {
|
|
191
|
+
max: number;
|
|
192
|
+
window: number;
|
|
193
|
+
debounce: number;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
declare function setRateLimitConfig(newConfig: typeof rateLimitConfig): void;
|
|
199
|
+
declare function getRateLimitConfig(): {
|
|
200
|
+
defaultRules: {
|
|
201
|
+
query: {
|
|
202
|
+
max: number;
|
|
203
|
+
window: number;
|
|
204
|
+
debounce: number;
|
|
205
|
+
};
|
|
206
|
+
mutation: {
|
|
207
|
+
max: number;
|
|
208
|
+
window: number;
|
|
209
|
+
debounce: number;
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
custom: {
|
|
213
|
+
login: {
|
|
214
|
+
max: number;
|
|
215
|
+
window: number;
|
|
216
|
+
debounce: number;
|
|
217
|
+
};
|
|
218
|
+
refreshToken: {
|
|
219
|
+
max: number;
|
|
220
|
+
window: number;
|
|
221
|
+
debounce: number;
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
|
|
145
226
|
interface QueryInput {
|
|
146
227
|
operationName: string;
|
|
147
228
|
fields?: FieldInput[];
|
|
@@ -363,4 +444,4 @@ declare function getBrowserDeviceInfo(): Promise<DeviceInfo>;
|
|
|
363
444
|
/** 跨平台获取设备信息 */
|
|
364
445
|
declare function getDeviceInfo(): Promise<DeviceInfo>;
|
|
365
446
|
|
|
366
|
-
export { type AggregateFieldInput, type BatchInsertInput, type BatchUpdateInput, type DeleteByIdInput, type DeleteInput, type DeviceInfo, type FieldInput, type FieldNode, type InsertOneInput, type LoginInput, type LogoutDeviceInput, type LogoutInput, type QueryAggregateInput, type QueryByIdInput, type QueryInput, type QueryPageListInput, type RefreshTokenInput, type RegisterUserInput, type RequestConfig, type RequestInterceptor, type SendCodeInput, type UpdateByPkInput, type UpdateInput, type UserToken, type VerifyCodeInput, type WhereInput, auth, buildCommonResultSelection, buildDataValue, buildFields, buildMutationFields, buildWhere, clearHeaders, formatGraphQLValue, generateOperationName, getBrowserDeviceInfo, getClient, getDeviceInfo, gql, initGraphQLClient, mutation, oss, query, removeHeader, removeToken, type requestResult, setEndpoint, setHeader, setHeaders, setToken, sms, toPascalCase, useInterceptor };
|
|
447
|
+
export { type AggregateFieldInput, type BatchInsertInput, type BatchUpdateInput, type DeleteByIdInput, type DeleteInput, type DeviceInfo, type FieldInput, type FieldNode, type InsertOneInput, type LoginInput, type LogoutDeviceInput, type LogoutInput, type QueryAggregateInput, type QueryByIdInput, type QueryInput, type QueryPageListInput, type RefreshTokenInput, type RegisterUserInput, type RequestConfig, type RequestInterceptor, type SendCodeInput, type UpdateByPkInput, type UpdateInput, type UserToken, type VerifyCodeInput, type WhereInput, auth, buildCommonResultSelection, buildDataValue, buildFields, buildMutationFields, buildWhere, clearHeaders, formatGraphQLValue, generateOperationName, getBrowserDeviceInfo, getClient, getDeviceInfo, getRateLimitConfig, gql, initGraphQLClient, mutation, oss, query, type rateLimitConfig$1 as rateLimitConfig, removeHeader, removeToken, type requestResult, setEndpoint, setHeader, setHeaders, setRateLimitConfig, setToken, sms, toPascalCase, useInterceptor };
|
package/dist/index.d.ts
CHANGED
|
@@ -59,6 +59,32 @@ interface UserToken {
|
|
|
59
59
|
/** 用户权限编码列表 */
|
|
60
60
|
permissions: string[];
|
|
61
61
|
}
|
|
62
|
+
interface rateLimitConfig$1 {
|
|
63
|
+
defaultRules: {
|
|
64
|
+
query: {
|
|
65
|
+
max: number;
|
|
66
|
+
window: number;
|
|
67
|
+
debounce: number;
|
|
68
|
+
};
|
|
69
|
+
mutation: {
|
|
70
|
+
max: number;
|
|
71
|
+
window: number;
|
|
72
|
+
debounce: number;
|
|
73
|
+
};
|
|
74
|
+
[key: string]: {
|
|
75
|
+
max: number;
|
|
76
|
+
window: number;
|
|
77
|
+
debounce: number;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
custom: {
|
|
81
|
+
[key: string]: {
|
|
82
|
+
max: number;
|
|
83
|
+
window: number;
|
|
84
|
+
debounce: number;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
}
|
|
62
88
|
|
|
63
89
|
declare class CCRequest {
|
|
64
90
|
private config;
|
|
@@ -142,6 +168,61 @@ declare function generateOperationName(entityName: string, original: string): st
|
|
|
142
168
|
declare function toPascalCase(str: string): string;
|
|
143
169
|
declare function buildCommonResultSelection(dataFields?: FieldInput[]): string;
|
|
144
170
|
|
|
171
|
+
declare const rateLimitConfig: {
|
|
172
|
+
defaultRules: {
|
|
173
|
+
query: {
|
|
174
|
+
max: number;
|
|
175
|
+
window: number;
|
|
176
|
+
debounce: number;
|
|
177
|
+
};
|
|
178
|
+
mutation: {
|
|
179
|
+
max: number;
|
|
180
|
+
window: number;
|
|
181
|
+
debounce: number;
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
custom: {
|
|
185
|
+
login: {
|
|
186
|
+
max: number;
|
|
187
|
+
window: number;
|
|
188
|
+
debounce: number;
|
|
189
|
+
};
|
|
190
|
+
refreshToken: {
|
|
191
|
+
max: number;
|
|
192
|
+
window: number;
|
|
193
|
+
debounce: number;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
declare function setRateLimitConfig(newConfig: typeof rateLimitConfig): void;
|
|
199
|
+
declare function getRateLimitConfig(): {
|
|
200
|
+
defaultRules: {
|
|
201
|
+
query: {
|
|
202
|
+
max: number;
|
|
203
|
+
window: number;
|
|
204
|
+
debounce: number;
|
|
205
|
+
};
|
|
206
|
+
mutation: {
|
|
207
|
+
max: number;
|
|
208
|
+
window: number;
|
|
209
|
+
debounce: number;
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
custom: {
|
|
213
|
+
login: {
|
|
214
|
+
max: number;
|
|
215
|
+
window: number;
|
|
216
|
+
debounce: number;
|
|
217
|
+
};
|
|
218
|
+
refreshToken: {
|
|
219
|
+
max: number;
|
|
220
|
+
window: number;
|
|
221
|
+
debounce: number;
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
|
|
145
226
|
interface QueryInput {
|
|
146
227
|
operationName: string;
|
|
147
228
|
fields?: FieldInput[];
|
|
@@ -363,4 +444,4 @@ declare function getBrowserDeviceInfo(): Promise<DeviceInfo>;
|
|
|
363
444
|
/** 跨平台获取设备信息 */
|
|
364
445
|
declare function getDeviceInfo(): Promise<DeviceInfo>;
|
|
365
446
|
|
|
366
|
-
export { type AggregateFieldInput, type BatchInsertInput, type BatchUpdateInput, type DeleteByIdInput, type DeleteInput, type DeviceInfo, type FieldInput, type FieldNode, type InsertOneInput, type LoginInput, type LogoutDeviceInput, type LogoutInput, type QueryAggregateInput, type QueryByIdInput, type QueryInput, type QueryPageListInput, type RefreshTokenInput, type RegisterUserInput, type RequestConfig, type RequestInterceptor, type SendCodeInput, type UpdateByPkInput, type UpdateInput, type UserToken, type VerifyCodeInput, type WhereInput, auth, buildCommonResultSelection, buildDataValue, buildFields, buildMutationFields, buildWhere, clearHeaders, formatGraphQLValue, generateOperationName, getBrowserDeviceInfo, getClient, getDeviceInfo, gql, initGraphQLClient, mutation, oss, query, removeHeader, removeToken, type requestResult, setEndpoint, setHeader, setHeaders, setToken, sms, toPascalCase, useInterceptor };
|
|
447
|
+
export { type AggregateFieldInput, type BatchInsertInput, type BatchUpdateInput, type DeleteByIdInput, type DeleteInput, type DeviceInfo, type FieldInput, type FieldNode, type InsertOneInput, type LoginInput, type LogoutDeviceInput, type LogoutInput, type QueryAggregateInput, type QueryByIdInput, type QueryInput, type QueryPageListInput, type RefreshTokenInput, type RegisterUserInput, type RequestConfig, type RequestInterceptor, type SendCodeInput, type UpdateByPkInput, type UpdateInput, type UserToken, type VerifyCodeInput, type WhereInput, auth, buildCommonResultSelection, buildDataValue, buildFields, buildMutationFields, buildWhere, clearHeaders, formatGraphQLValue, generateOperationName, getBrowserDeviceInfo, getClient, getDeviceInfo, getRateLimitConfig, gql, initGraphQLClient, mutation, oss, query, type rateLimitConfig$1 as rateLimitConfig, removeHeader, removeToken, type requestResult, setEndpoint, setHeader, setHeaders, setRateLimitConfig, setToken, sms, toPascalCase, useInterceptor };
|
package/dist/index.js
CHANGED
|
@@ -970,7 +970,7 @@ function formatGraphQLValue(value) {
|
|
|
970
970
|
if (value === null) return "null";
|
|
971
971
|
if (typeof value === "string") {
|
|
972
972
|
if (value.startsWith("$")) return value;
|
|
973
|
-
if (/^[A-
|
|
973
|
+
if (/^[A-Z_]+$/.test(value)) return value;
|
|
974
974
|
return JSON.stringify(value);
|
|
975
975
|
}
|
|
976
976
|
if (typeof value === "number" || typeof value === "boolean") {
|
|
@@ -1405,8 +1405,8 @@ function buildGraphQLGetFilePreview(resourceId) {
|
|
|
1405
1405
|
// src/rateLimit/rateLimitConfig.ts
|
|
1406
1406
|
var rateLimitConfig = {
|
|
1407
1407
|
defaultRules: {
|
|
1408
|
-
query: { max:
|
|
1409
|
-
mutation: { max:
|
|
1408
|
+
query: { max: 20, window: 1, debounce: 0 },
|
|
1409
|
+
mutation: { max: 10, window: 1, debounce: 200 }
|
|
1410
1410
|
},
|
|
1411
1411
|
custom: {
|
|
1412
1412
|
login: { max: 1, window: 5, debounce: 0 },
|
|
@@ -1415,11 +1415,18 @@ var rateLimitConfig = {
|
|
|
1415
1415
|
};
|
|
1416
1416
|
|
|
1417
1417
|
// src/rateLimit/rateLimit.ts
|
|
1418
|
+
var globalConfig = rateLimitConfig;
|
|
1419
|
+
function setRateLimitConfig(newConfig) {
|
|
1420
|
+
globalConfig = newConfig;
|
|
1421
|
+
}
|
|
1422
|
+
function getRateLimitConfig() {
|
|
1423
|
+
return globalConfig;
|
|
1424
|
+
}
|
|
1418
1425
|
var trackers = /* @__PURE__ */ new Map();
|
|
1419
1426
|
function getRule(operateName, type, config) {
|
|
1420
1427
|
return config.custom?.[operateName] || config.defaultRules[type];
|
|
1421
1428
|
}
|
|
1422
|
-
function rateLimit(operateName, type, fn, config =
|
|
1429
|
+
function rateLimit(operateName, type, fn, config = globalConfig) {
|
|
1423
1430
|
const rule = getRule(operateName, type, config);
|
|
1424
1431
|
const now = Date.now();
|
|
1425
1432
|
const key = `${type}::${operateName}`;
|
|
@@ -1474,7 +1481,7 @@ var auth = {
|
|
|
1474
1481
|
setLoginInfo(result.login, input.remember);
|
|
1475
1482
|
clearCache();
|
|
1476
1483
|
return result;
|
|
1477
|
-
}
|
|
1484
|
+
});
|
|
1478
1485
|
},
|
|
1479
1486
|
async refreshToken(input) {
|
|
1480
1487
|
return rateLimit("refreshToken", "mutation", async () => {
|
|
@@ -1483,7 +1490,7 @@ var auth = {
|
|
|
1483
1490
|
setLoginInfo(result.refreshToken, input.remember);
|
|
1484
1491
|
clearCache();
|
|
1485
1492
|
return result;
|
|
1486
|
-
}
|
|
1493
|
+
});
|
|
1487
1494
|
},
|
|
1488
1495
|
async register(input) {
|
|
1489
1496
|
return rateLimit("registerUser", "mutation", async () => {
|
|
@@ -1491,7 +1498,7 @@ var auth = {
|
|
|
1491
1498
|
const result = await execute({ query: query2, variables });
|
|
1492
1499
|
clearCache();
|
|
1493
1500
|
return result;
|
|
1494
|
-
}
|
|
1501
|
+
});
|
|
1495
1502
|
},
|
|
1496
1503
|
async logout() {
|
|
1497
1504
|
return rateLimit("logout", "mutation", async () => {
|
|
@@ -1500,7 +1507,7 @@ var auth = {
|
|
|
1500
1507
|
removeLoginInfo();
|
|
1501
1508
|
clearCache();
|
|
1502
1509
|
return result;
|
|
1503
|
-
}
|
|
1510
|
+
});
|
|
1504
1511
|
},
|
|
1505
1512
|
async logoutAllDevices() {
|
|
1506
1513
|
return rateLimit("logoutAllDevices", "mutation", async () => {
|
|
@@ -1509,7 +1516,7 @@ var auth = {
|
|
|
1509
1516
|
removeLoginInfo();
|
|
1510
1517
|
clearCache();
|
|
1511
1518
|
return result;
|
|
1512
|
-
}
|
|
1519
|
+
});
|
|
1513
1520
|
},
|
|
1514
1521
|
async logoutDevice(deviceId) {
|
|
1515
1522
|
return rateLimit("logoutDevice", "mutation", async () => {
|
|
@@ -1520,7 +1527,7 @@ var auth = {
|
|
|
1520
1527
|
}
|
|
1521
1528
|
clearCache();
|
|
1522
1529
|
return result;
|
|
1523
|
-
}
|
|
1530
|
+
});
|
|
1524
1531
|
}
|
|
1525
1532
|
};
|
|
1526
1533
|
|
|
@@ -1974,7 +1981,7 @@ var oss = {
|
|
|
1974
1981
|
const { query: query2, variables } = buildGraphQLUploadPresignedUrl(presignedInput);
|
|
1975
1982
|
const result = await execute({ query: query2, variables });
|
|
1976
1983
|
return result;
|
|
1977
|
-
}
|
|
1984
|
+
});
|
|
1978
1985
|
console.log("presignedResult====>", presignedResult);
|
|
1979
1986
|
if (!presignedResult.uploadPresignedUrl) throw new Error("\u83B7\u53D6\u9884\u7B7E\u540D URL \u5931\u8D25");
|
|
1980
1987
|
const { uploadUrl, uploadHeaders, downloadUrl, resourceId, contentType, originalFileName } = presignedResult.uploadPresignedUrl;
|
|
@@ -2035,7 +2042,7 @@ var oss = {
|
|
|
2035
2042
|
const { query: query2, variables } = buildGraphQLUploadPresignedUrl(presignedInput);
|
|
2036
2043
|
const result = await execute({ query: query2, variables });
|
|
2037
2044
|
return result;
|
|
2038
|
-
}
|
|
2045
|
+
});
|
|
2039
2046
|
if (!presignedResult.uploadPresignedUrl) throw new Error("\u83B7\u53D6\u9884\u7B7E\u540D URL \u5931\u8D25");
|
|
2040
2047
|
const { uploadUrl, uploadHeaders, downloadUrl, resourceId, contentType, originalFileName } = presignedResult.uploadPresignedUrl;
|
|
2041
2048
|
const headers = {};
|
|
@@ -2063,7 +2070,7 @@ var oss = {
|
|
|
2063
2070
|
const { query: query2, variables } = buildGraphQLGetFilePreview(resourceId);
|
|
2064
2071
|
const result = await execute({ query: query2, variables });
|
|
2065
2072
|
return result;
|
|
2066
|
-
}
|
|
2073
|
+
});
|
|
2067
2074
|
}
|
|
2068
2075
|
};
|
|
2069
2076
|
export {
|
|
@@ -2072,6 +2079,7 @@ export {
|
|
|
2072
2079
|
getBrowserDeviceInfo,
|
|
2073
2080
|
getClient,
|
|
2074
2081
|
getDeviceInfo,
|
|
2082
|
+
getRateLimitConfig,
|
|
2075
2083
|
gql,
|
|
2076
2084
|
initGraphQLClient,
|
|
2077
2085
|
mutation,
|
|
@@ -2082,6 +2090,7 @@ export {
|
|
|
2082
2090
|
setEndpoint,
|
|
2083
2091
|
setHeader,
|
|
2084
2092
|
setHeaders,
|
|
2093
|
+
setRateLimitConfig,
|
|
2085
2094
|
setToken,
|
|
2086
2095
|
sms,
|
|
2087
2096
|
useInterceptor
|