@ganju/utils 0.0.1
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/LICENSE +201 -0
- package/NOTICE +9 -0
- package/README.md +23 -0
- package/dist/apiError.d.ts +3 -0
- package/dist/apiError.d.ts.map +1 -0
- package/dist/apiError.js +36 -0
- package/dist/attachment.d.ts +33 -0
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +59 -0
- package/dist/base64.d.ts +10 -0
- package/dist/base64.d.ts.map +1 -0
- package/dist/base64.js +50 -0
- package/dist/channelDebounce.d.ts +26 -0
- package/dist/channelDebounce.d.ts.map +1 -0
- package/dist/channelDebounce.js +35 -0
- package/dist/channelNotifier.d.ts +9 -0
- package/dist/channelNotifier.d.ts.map +1 -0
- package/dist/channelNotifier.js +31 -0
- package/dist/chunking.d.ts +28 -0
- package/dist/chunking.d.ts.map +1 -0
- package/dist/chunking.js +97 -0
- package/dist/cliConstants.d.ts +9 -0
- package/dist/cliConstants.d.ts.map +1 -0
- package/dist/cliConstants.js +47 -0
- package/dist/coerce.d.ts +2 -0
- package/dist/coerce.d.ts.map +1 -0
- package/dist/coerce.js +13 -0
- package/dist/constants.d.ts +624 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +2220 -0
- package/dist/crypto.d.ts +14 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +93 -0
- package/dist/customCodeProject.d.ts +91 -0
- package/dist/customCodeProject.d.ts.map +1 -0
- package/dist/customCodeProject.js +154 -0
- package/dist/customCodeToken.d.ts +41 -0
- package/dist/customCodeToken.d.ts.map +1 -0
- package/dist/customCodeToken.js +115 -0
- package/dist/deadline.d.ts +6 -0
- package/dist/deadline.d.ts.map +1 -0
- package/dist/deadline.js +45 -0
- package/dist/discordSend.d.ts +25 -0
- package/dist/discordSend.d.ts.map +1 -0
- package/dist/discordSend.js +8 -0
- package/dist/embeddable.d.ts +2 -0
- package/dist/embeddable.d.ts.map +1 -0
- package/dist/embeddable.js +6 -0
- package/dist/exposedResource.d.ts +6 -0
- package/dist/exposedResource.d.ts.map +1 -0
- package/dist/exposedResource.js +18 -0
- package/dist/extractedDocument.d.ts +70 -0
- package/dist/extractedDocument.d.ts.map +1 -0
- package/dist/extractedDocument.js +2 -0
- package/dist/fetcher.d.ts +8 -0
- package/dist/fetcher.d.ts.map +1 -0
- package/dist/fetcher.js +68 -0
- package/dist/formatFilename.d.ts +2 -0
- package/dist/formatFilename.d.ts.map +1 -0
- package/dist/formatFilename.js +19 -0
- package/dist/formatRelative.d.ts +12 -0
- package/dist/formatRelative.d.ts.map +1 -0
- package/dist/formatRelative.js +28 -0
- package/dist/formatRelativeTime.d.ts +2 -0
- package/dist/formatRelativeTime.d.ts.map +1 -0
- package/dist/formatRelativeTime.js +49 -0
- package/dist/getEnv.d.ts +5 -0
- package/dist/getEnv.d.ts.map +1 -0
- package/dist/getEnv.js +11 -0
- package/dist/gmailSend.d.ts +24 -0
- package/dist/gmailSend.d.ts.map +1 -0
- package/dist/gmailSend.js +9 -0
- package/dist/index.d.ts +2839 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +155 -0
- package/dist/jsonSchemaToZodShape.d.ts +38 -0
- package/dist/jsonSchemaToZodShape.d.ts.map +1 -0
- package/dist/jsonSchemaToZodShape.js +117 -0
- package/dist/l2Normalize.d.ts +2 -0
- package/dist/l2Normalize.d.ts.map +1 -0
- package/dist/l2Normalize.js +25 -0
- package/dist/languageCookieDomain.d.ts +21 -0
- package/dist/languageCookieDomain.d.ts.map +1 -0
- package/dist/languageCookieDomain.js +39 -0
- package/dist/localizeZodIssue.d.ts +43 -0
- package/dist/localizeZodIssue.d.ts.map +1 -0
- package/dist/localizeZodIssue.js +90 -0
- package/dist/mailHeaders.d.ts +4 -0
- package/dist/mailHeaders.d.ts.map +1 -0
- package/dist/mailHeaders.js +11 -0
- package/dist/mcpProxy.d.ts +2 -0
- package/dist/mcpProxy.d.ts.map +1 -0
- package/dist/mcpProxy.js +21 -0
- package/dist/mimeMessage.d.ts +21 -0
- package/dist/mimeMessage.d.ts.map +1 -0
- package/dist/mimeMessage.js +58 -0
- package/dist/oauth.d.ts +21 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +75 -0
- package/dist/oauthProviders.d.ts +12 -0
- package/dist/oauthProviders.d.ts.map +1 -0
- package/dist/oauthProviders.js +99 -0
- package/dist/outlookSend.d.ts +19 -0
- package/dist/outlookSend.d.ts.map +1 -0
- package/dist/outlookSend.js +9 -0
- package/dist/parseHttpError.d.ts +2 -0
- package/dist/parseHttpError.d.ts.map +1 -0
- package/dist/parseHttpError.js +23 -0
- package/dist/planLimitError.d.ts +18 -0
- package/dist/planLimitError.d.ts.map +1 -0
- package/dist/planLimitError.js +35 -0
- package/dist/processQueueBatch.d.ts +17 -0
- package/dist/processQueueBatch.d.ts.map +1 -0
- package/dist/processQueueBatch.js +32 -0
- package/dist/reservedToolName.d.ts +16 -0
- package/dist/reservedToolName.d.ts.map +1 -0
- package/dist/reservedToolName.js +25 -0
- package/dist/resourceUri.d.ts +2 -0
- package/dist/resourceUri.d.ts.map +1 -0
- package/dist/resourceUri.js +19 -0
- package/dist/retry.d.ts +10 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +37 -0
- package/dist/sanitize.d.ts +7 -0
- package/dist/sanitize.d.ts.map +1 -0
- package/dist/sanitize.js +69 -0
- package/dist/schema.d.ts +2175 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +1382 -0
- package/dist/sdkConstants.d.ts +15 -0
- package/dist/sdkConstants.d.ts.map +1 -0
- package/dist/sdkConstants.js +43 -0
- package/dist/slackSend.d.ts +38 -0
- package/dist/slackSend.d.ts.map +1 -0
- package/dist/slackSend.js +14 -0
- package/dist/slug.d.ts +5 -0
- package/dist/slug.d.ts.map +1 -0
- package/dist/slug.js +34 -0
- package/dist/slugifyTitle.d.ts +2 -0
- package/dist/slugifyTitle.d.ts.map +1 -0
- package/dist/slugifyTitle.js +11 -0
- package/dist/sources.d.ts +43 -0
- package/dist/sources.d.ts.map +1 -0
- package/dist/sources.js +73 -0
- package/dist/ssrf.d.ts +3 -0
- package/dist/ssrf.d.ts.map +1 -0
- package/dist/ssrf.js +46 -0
- package/dist/tallyUsageKinds.d.ts +9 -0
- package/dist/tallyUsageKinds.d.ts.map +1 -0
- package/dist/tallyUsageKinds.js +20 -0
- package/dist/telegramSend.d.ts +28 -0
- package/dist/telegramSend.d.ts.map +1 -0
- package/dist/telegramSend.js +9 -0
- package/dist/toolCatalog.d.ts +452 -0
- package/dist/toolCatalog.d.ts.map +1 -0
- package/dist/toolCatalog.js +552 -0
- package/dist/validateMessageVariables.d.ts +7 -0
- package/dist/validateMessageVariables.d.ts.map +1 -0
- package/dist/validateMessageVariables.js +16 -0
- package/dist/vendorError.d.ts +2 -0
- package/dist/vendorError.d.ts.map +1 -0
- package/dist/vendorError.js +25 -0
- package/dist/whatsappSend.d.ts +31 -0
- package/dist/whatsappSend.d.ts.map +1 -0
- package/dist/whatsappSend.js +11 -0
- package/package.json +76 -0
- package/src/apiError.ts +40 -0
- package/src/attachment.ts +97 -0
- package/src/base64.ts +60 -0
- package/src/channelDebounce.ts +76 -0
- package/src/channelNotifier.ts +39 -0
- package/src/chunking.ts +131 -0
- package/src/cliConstants.ts +50 -0
- package/src/coerce.ts +9 -0
- package/src/constants.ts +2542 -0
- package/src/crypto.ts +108 -0
- package/src/customCodeProject.ts +182 -0
- package/src/customCodeToken.ts +198 -0
- package/src/deadline.ts +43 -0
- package/src/discordSend.ts +41 -0
- package/src/embeddable.ts +4 -0
- package/src/exposedResource.ts +40 -0
- package/src/extractedDocument.ts +62 -0
- package/src/fetcher.ts +82 -0
- package/src/formatFilename.ts +19 -0
- package/src/formatRelative.ts +36 -0
- package/src/formatRelativeTime.ts +45 -0
- package/src/getEnv.ts +13 -0
- package/src/gmailSend.ts +34 -0
- package/src/index.ts +397 -0
- package/src/jsonSchemaToZodShape.ts +111 -0
- package/src/l2Normalize.ts +19 -0
- package/src/languageCookieDomain.ts +37 -0
- package/src/localizeZodIssue.ts +124 -0
- package/src/mailHeaders.ts +12 -0
- package/src/mcpProxy.ts +20 -0
- package/src/mimeMessage.ts +82 -0
- package/src/oauth.ts +103 -0
- package/src/oauthProviders.ts +118 -0
- package/src/outlookSend.ts +44 -0
- package/src/parseHttpError.ts +16 -0
- package/src/planLimitError.ts +50 -0
- package/src/processQueueBatch.ts +46 -0
- package/src/reservedToolName.ts +27 -0
- package/src/resourceUri.ts +17 -0
- package/src/retry.ts +43 -0
- package/src/sanitize.ts +67 -0
- package/src/schema.ts +1624 -0
- package/src/sdkConstants.ts +44 -0
- package/src/slackSend.ts +65 -0
- package/src/slug.ts +37 -0
- package/src/slugifyTitle.ts +8 -0
- package/src/sources.ts +117 -0
- package/src/ssrf.ts +34 -0
- package/src/tallyUsageKinds.ts +20 -0
- package/src/telegramSend.ts +39 -0
- package/src/toolCatalog.ts +635 -0
- package/src/validateMessageVariables.ts +18 -0
- package/src/vendorError.ts +19 -0
- package/src/whatsappSend.ts +47 -0
package/dist/chunking.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareChunks = exports.buildHeader = exports.chunkText = exports.splitRecursive = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const trySplit = (text, sep) => {
|
|
6
|
+
if (typeof sep === 'string') {
|
|
7
|
+
return text.includes(sep) ? text.split(sep) : null;
|
|
8
|
+
}
|
|
9
|
+
return sep.test(text) ? text.split(sep) : null;
|
|
10
|
+
};
|
|
11
|
+
const splitRecursive = (text, target, separators = constants_1.constants.CHUNK_SEPARATORS) => {
|
|
12
|
+
if (text.length <= target)
|
|
13
|
+
return [text];
|
|
14
|
+
for (const { split, join } of separators) {
|
|
15
|
+
const parts = trySplit(text, split);
|
|
16
|
+
if (!parts)
|
|
17
|
+
continue;
|
|
18
|
+
const chunks = [];
|
|
19
|
+
let current = '';
|
|
20
|
+
for (const part of parts) {
|
|
21
|
+
const piece = current ? current + join + part : part;
|
|
22
|
+
if (piece.length > target && current) {
|
|
23
|
+
chunks.push(current);
|
|
24
|
+
current = part;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
current = piece;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (current)
|
|
31
|
+
chunks.push(current);
|
|
32
|
+
return chunks.flatMap(chunk => chunk.length > target ? (0, exports.splitRecursive)(chunk, target, separators) : [chunk]);
|
|
33
|
+
}
|
|
34
|
+
const chunks = [];
|
|
35
|
+
for (let i = 0; i < text.length; i += target) {
|
|
36
|
+
chunks.push(text.slice(i, i + target));
|
|
37
|
+
}
|
|
38
|
+
return chunks;
|
|
39
|
+
};
|
|
40
|
+
exports.splitRecursive = splitRecursive;
|
|
41
|
+
const chunkText = (text, options) => {
|
|
42
|
+
const target = options?.targetChars ?? constants_1.constants.CHUNK_TARGET_CHARS;
|
|
43
|
+
const overlap = options?.overlapChars ?? constants_1.constants.CHUNK_OVERLAP_CHARS;
|
|
44
|
+
const trimmed = text.trim();
|
|
45
|
+
if (!trimmed)
|
|
46
|
+
return [];
|
|
47
|
+
if (trimmed.length <= target)
|
|
48
|
+
return [trimmed];
|
|
49
|
+
const rawChunks = (0, exports.splitRecursive)(trimmed, target);
|
|
50
|
+
const withOverlap = [];
|
|
51
|
+
for (let i = 0; i < rawChunks.length; i++) {
|
|
52
|
+
const prev = i > 0 ? rawChunks[i - 1].slice(-overlap) : '';
|
|
53
|
+
withOverlap.push((prev ? prev + '\n' : '') + rawChunks[i]);
|
|
54
|
+
}
|
|
55
|
+
return withOverlap.filter(c => c.trim().length > 0);
|
|
56
|
+
};
|
|
57
|
+
exports.chunkText = chunkText;
|
|
58
|
+
const buildHeader = (input) => [
|
|
59
|
+
input.title ? `Title: ${input.title}` : null,
|
|
60
|
+
input.description ? `Description: ${input.description}` : null,
|
|
61
|
+
input.uri ? `URI: ${input.uri}` : null,
|
|
62
|
+
input.mimeType ? `MimeType: ${input.mimeType}` : null,
|
|
63
|
+
input.fileName ? `FileName: ${input.fileName}` : null
|
|
64
|
+
]
|
|
65
|
+
.filter(Boolean)
|
|
66
|
+
.join('\n');
|
|
67
|
+
exports.buildHeader = buildHeader;
|
|
68
|
+
const prepareChunks = (header, documents, fallbackContent, options) => {
|
|
69
|
+
if (documents && documents.length > 0) {
|
|
70
|
+
const out = [];
|
|
71
|
+
documents.forEach((doc, docIndex) => {
|
|
72
|
+
const body = (doc.pageContent || '').replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, '').trim();
|
|
73
|
+
if (!body)
|
|
74
|
+
return;
|
|
75
|
+
const text = docIndex === 0 && header ? `${header}\n\n${body}` : body;
|
|
76
|
+
const pieces = (0, exports.chunkText)(text, options);
|
|
77
|
+
pieces.forEach((piece, pieceIndex) => {
|
|
78
|
+
out.push({
|
|
79
|
+
content: piece,
|
|
80
|
+
metadata: {
|
|
81
|
+
...doc.metadata,
|
|
82
|
+
chunkIndexInPage: pieceIndex,
|
|
83
|
+
chunksInPage: pieces.length
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
const body = (fallbackContent || '').replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, '').trim();
|
|
91
|
+
const fullText = [header, body].filter(Boolean).join('\n\n');
|
|
92
|
+
return (0, exports.chunkText)(fullText, options).map(content => ({
|
|
93
|
+
content,
|
|
94
|
+
metadata: null
|
|
95
|
+
}));
|
|
96
|
+
};
|
|
97
|
+
exports.prepareChunks = prepareChunks;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const CLI_OAUTH_CLIENT_NAME = "Ganju CLI";
|
|
2
|
+
export declare const CLI_OAUTH_REDIRECT_PATH = "/callback";
|
|
3
|
+
export declare const CLI_OAUTH_REDIRECT_PORTS: number[];
|
|
4
|
+
export declare const CLI_OAUTH_SCOPES: string[];
|
|
5
|
+
export declare const CLI_TOKEN_REFRESH_SKEW_SECONDS = 60;
|
|
6
|
+
export declare const CUSTOM_CODE_SDK_SPECIFIER = "./ganju-sdk.js";
|
|
7
|
+
export declare const CUSTOM_CODE_MAX_BUNDLE_BYTES: number;
|
|
8
|
+
export declare const CREDENTIAL_PROVIDER_CUSTOM_CODE: "custom-code";
|
|
9
|
+
//# sourceMappingURL=cliConstants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cliConstants.d.ts","sourceRoot":"","sources":["../src/cliConstants.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,qBAAqB,cAAc,CAAC;AACjD,eAAO,MAAM,uBAAuB,cAAc,CAAC;AACnD,eAAO,MAAM,wBAAwB,UAAiC,CAAC;AAIvE,eAAO,MAAM,gBAAgB,UAK5B,CAAC;AAIF,eAAO,MAAM,8BAA8B,KAAK,CAAC;AAIjD,eAAO,MAAM,yBAAyB,mBAAmB,CAAC;AAI1D,eAAO,MAAM,4BAA4B,QAAkB,CAAC;AAK5D,eAAO,MAAM,+BAA+B,EAAoB,aAAa,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The handful of constants that get bundled into the published `ganju` CLI,
|
|
3
|
+
// split out of the main constants module for exactly that reason.
|
|
4
|
+
//
|
|
5
|
+
// The same problem `sdkConstants.ts` solves, with a sharper edge. `constants.ts`
|
|
6
|
+
// is one large object literal, so a bundler cannot drop the keys a consumer
|
|
7
|
+
// doesn't touch — and the CLI ships to npm, where those keys would be plan
|
|
8
|
+
// limits, pricing, vendor scopes and internal URLs sitting readable inside a
|
|
9
|
+
// public package. Eight values live here instead, and the main module
|
|
10
|
+
// re-exports them so there is still one definition of each.
|
|
11
|
+
//
|
|
12
|
+
// The rule for this file: nothing lands here unless the CLI reads it, and it
|
|
13
|
+
// imports nothing.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CREDENTIAL_PROVIDER_CUSTOM_CODE = exports.CUSTOM_CODE_MAX_BUNDLE_BYTES = exports.CUSTOM_CODE_SDK_SPECIFIER = exports.CLI_TOKEN_REFRESH_SKEW_SECONDS = exports.CLI_OAUTH_SCOPES = exports.CLI_OAUTH_REDIRECT_PORTS = exports.CLI_OAUTH_REDIRECT_PATH = exports.CLI_OAUTH_CLIENT_NAME = void 0;
|
|
16
|
+
// How `ganju login` identifies itself, and where it listens for the redirect.
|
|
17
|
+
//
|
|
18
|
+
// A fixed port would fail whenever something else already held it, so the CLI
|
|
19
|
+
// binds the first one here that is free. All of them are registered up front
|
|
20
|
+
// rather than only the one that gets used: the provider does implement RFC 8252
|
|
21
|
+
// loopback matching, where the port is ignored for a 127.0.0.0/8 redirect, but
|
|
22
|
+
// that is one library's behaviour and this is a login that has already opened
|
|
23
|
+
// someone's browser by the time it would fail.
|
|
24
|
+
exports.CLI_OAUTH_CLIENT_NAME = 'Ganju CLI';
|
|
25
|
+
exports.CLI_OAUTH_REDIRECT_PATH = '/callback';
|
|
26
|
+
exports.CLI_OAUTH_REDIRECT_PORTS = [8976, 8977, 8978, 8979, 8980];
|
|
27
|
+
// `offline_access` is what mints the refresh token; without it a CLI session
|
|
28
|
+
// would end an hour after login.
|
|
29
|
+
exports.CLI_OAUTH_SCOPES = [
|
|
30
|
+
'openid',
|
|
31
|
+
'profile',
|
|
32
|
+
'email',
|
|
33
|
+
'offline_access'
|
|
34
|
+
];
|
|
35
|
+
// Refresh this far before the access token actually expires, so a long command
|
|
36
|
+
// can't have its token die mid-request.
|
|
37
|
+
exports.CLI_TOKEN_REFRESH_SKEW_SECONDS = 60;
|
|
38
|
+
// What `ganju build` rewrites the SDK import to. The deployed script imports the
|
|
39
|
+
// sibling module the publish pipeline attaches, whatever the author typed.
|
|
40
|
+
exports.CUSTOM_CODE_SDK_SPECIFIER = './ganju-sdk.js';
|
|
41
|
+
// Set well below Cloudflare's own script-size ceiling so a rejection happens
|
|
42
|
+
// with a legible error rather than at deploy time.
|
|
43
|
+
exports.CUSTOM_CODE_MAX_BUNDLE_BYTES = 3 * 1024 * 1024;
|
|
44
|
+
// The provider `ganju secret` writes under. custom-code secrets are the
|
|
45
|
+
// `ctx.secret(name)` values a user script reads at runtime, addressed by the
|
|
46
|
+
// label in each row's metadata.
|
|
47
|
+
exports.CREDENTIAL_PROVIDER_CUSTOM_CODE = 'custom-code';
|
package/dist/coerce.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce.d.ts","sourceRoot":"","sources":["../src/coerce.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,KAAG,MAAM,EAQpD,CAAC"}
|
package/dist/coerce.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toStringArray = void 0;
|
|
4
|
+
const toStringArray = (input) => {
|
|
5
|
+
if (Array.isArray(input)) {
|
|
6
|
+
return input.map(s => String(s).trim()).filter(Boolean);
|
|
7
|
+
}
|
|
8
|
+
if (typeof input === 'string' && input.trim()) {
|
|
9
|
+
return input.split(',').map(s => s.trim()).filter(Boolean);
|
|
10
|
+
}
|
|
11
|
+
return [];
|
|
12
|
+
};
|
|
13
|
+
exports.toStringArray = toStringArray;
|