@ganju/utils 0.0.6 → 0.0.9
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/attachment.d.ts.map +1 -1
- package/dist/chunking.d.ts.map +1 -1
- package/dist/chunking.js +9 -3
- package/dist/coerce.d.ts.map +1 -1
- package/dist/coerce.js +4 -1
- package/dist/constants.d.ts +27 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +157 -22
- package/dist/containmentToken.d.ts +25 -0
- package/dist/containmentToken.d.ts.map +1 -0
- package/dist/containmentToken.js +81 -0
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js +4 -1
- package/dist/getEnv.d.ts.map +1 -1
- package/dist/index.d.ts +34 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/llmBaseUrl.d.ts +39 -0
- package/dist/llmBaseUrl.d.ts.map +1 -0
- package/dist/llmBaseUrl.js +65 -0
- package/dist/localizeZodIssue.d.ts.map +1 -1
- package/dist/localizeZodIssue.js +6 -0
- package/dist/oauth.d.ts.map +1 -1
- package/dist/parseHttpError.d.ts.map +1 -1
- package/dist/schema.d.ts +2 -2
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +32 -8
- package/dist/sources.d.ts.map +1 -1
- package/dist/vendorError.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/attachment.ts +2 -1
- package/src/chunking.ts +9 -3
- package/src/coerce.ts +4 -1
- package/src/constants.ts +178 -22
- package/src/containmentToken.ts +146 -0
- package/src/crypto.ts +6 -2
- package/src/getEnv.ts +1 -4
- package/src/index.ts +16 -0
- package/src/llmBaseUrl.ts +65 -0
- package/src/localizeZodIssue.ts +6 -0
- package/src/oauth.ts +1 -3
- package/src/parseHttpError.ts +3 -1
- package/src/schema.ts +63 -11
- package/src/slackSend.ts +10 -10
- package/src/sources.ts +7 -2
- package/src/vendorError.ts +4 -1
package/dist/attachment.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachment.d.ts","sourceRoot":"","sources":["../src/attachment.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"attachment.d.ts","sourceRoot":"","sources":["../src/attachment.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,uBAAuB,GAC/B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,UAAU,EAAE,kBAAkB,CAAA;CAAE,GAC5C;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAU,kBAAkB,EAC5B,YAAY,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,EACxD,OAAM,QAAQ,GAAG,QAAmB,KACnC,OAAO,CAAC,uBAAuB,CAiDjC,CAAC"}
|
package/dist/chunking.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunking.d.ts","sourceRoot":"","sources":["../src/chunking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,KAAK,EACV,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,qBAAqB,CAAC;AAE7B,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AASpE,eAAO,MAAM,cAAc,GACzB,MAAM,MAAM,EACZ,QAAQ,MAAM,EACd,aAAY,SAAS,SAAS,EAA+B,KAC5D,MAAM,
|
|
1
|
+
{"version":3,"file":"chunking.d.ts","sourceRoot":"","sources":["../src/chunking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,KAAK,EACV,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,qBAAqB,CAAC;AAE7B,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AASpE,eAAO,MAAM,cAAc,GACzB,MAAM,MAAM,EACZ,QAAQ,MAAM,EACd,aAAY,SAAS,SAAS,EAA+B,KAC5D,MAAM,EA8BR,CAAC;AAEF,eAAO,MAAM,SAAS,GACpB,MAAM,MAAM,EACZ,UAAU;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,KACxD,MAAM,EAeR,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,OAAO;IACjC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,KAAG,MASW,CAAC;AAEhB,MAAM,WAAW,aAAc,SAAQ,yBAAyB;IAC9D,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;CAChC;AAED,eAAO,MAAM,aAAa,GACxB,QAAQ,MAAM,EACd,WAAW,iBAAiB,EAAE,GAAG,IAAI,EACrC,iBAAiB,MAAM,GAAG,IAAI,EAC9B,UAAU;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,KACxD,aAAa,EAgCf,CAAC"}
|
package/dist/chunking.js
CHANGED
|
@@ -29,7 +29,9 @@ const splitRecursive = (text, target, separators = constants_1.constants.CHUNK_S
|
|
|
29
29
|
}
|
|
30
30
|
if (current)
|
|
31
31
|
chunks.push(current);
|
|
32
|
-
return chunks.flatMap(chunk => chunk.length > target
|
|
32
|
+
return chunks.flatMap(chunk => chunk.length > target
|
|
33
|
+
? (0, exports.splitRecursive)(chunk, target, separators)
|
|
34
|
+
: [chunk]);
|
|
33
35
|
}
|
|
34
36
|
const chunks = [];
|
|
35
37
|
for (let i = 0; i < text.length; i += target) {
|
|
@@ -69,7 +71,9 @@ const prepareChunks = (header, documents, fallbackContent, options) => {
|
|
|
69
71
|
if (documents && documents.length > 0) {
|
|
70
72
|
const out = [];
|
|
71
73
|
documents.forEach((doc, docIndex) => {
|
|
72
|
-
const body = (doc.pageContent || '')
|
|
74
|
+
const body = (doc.pageContent || '')
|
|
75
|
+
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, '')
|
|
76
|
+
.trim();
|
|
73
77
|
if (!body)
|
|
74
78
|
return;
|
|
75
79
|
const text = docIndex === 0 && header ? `${header}\n\n${body}` : body;
|
|
@@ -87,7 +91,9 @@ const prepareChunks = (header, documents, fallbackContent, options) => {
|
|
|
87
91
|
});
|
|
88
92
|
return out;
|
|
89
93
|
}
|
|
90
|
-
const body = (fallbackContent || '')
|
|
94
|
+
const body = (fallbackContent || '')
|
|
95
|
+
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, '')
|
|
96
|
+
.trim();
|
|
91
97
|
const fullText = [header, body].filter(Boolean).join('\n\n');
|
|
92
98
|
return (0, exports.chunkText)(fullText, options).map(content => ({
|
|
93
99
|
content,
|
package/dist/coerce.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coerce.d.ts","sourceRoot":"","sources":["../src/coerce.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,KAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"coerce.d.ts","sourceRoot":"","sources":["../src/coerce.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,KAAG,MAAM,EAWpD,CAAC"}
|
package/dist/coerce.js
CHANGED
|
@@ -6,7 +6,10 @@ const toStringArray = (input) => {
|
|
|
6
6
|
return input.map(s => String(s).trim()).filter(Boolean);
|
|
7
7
|
}
|
|
8
8
|
if (typeof input === 'string' && input.trim()) {
|
|
9
|
-
return input
|
|
9
|
+
return input
|
|
10
|
+
.split(',')
|
|
11
|
+
.map(s => s.trim())
|
|
12
|
+
.filter(Boolean);
|
|
10
13
|
}
|
|
11
14
|
return [];
|
|
12
15
|
};
|
package/dist/constants.d.ts
CHANGED
|
@@ -55,6 +55,8 @@ interface PlanLimits {
|
|
|
55
55
|
canUseCustomLlm: boolean;
|
|
56
56
|
canUseCustomCode: boolean;
|
|
57
57
|
maxHttpEndpointsPerArtifact: number | null;
|
|
58
|
+
includedToolCalls: number;
|
|
59
|
+
toolCallHardCap: number | null;
|
|
58
60
|
includedMessages: number;
|
|
59
61
|
includedEmbeddedBytes: number;
|
|
60
62
|
}
|
|
@@ -85,6 +87,9 @@ export declare const constants: {
|
|
|
85
87
|
PRICING_INCLUDED_EMBEDDED_GB: number;
|
|
86
88
|
PRICING_MESSAGE_PER_1K_USD: number;
|
|
87
89
|
PRICING_EMBEDDED_PER_GB_USD: number;
|
|
90
|
+
PRICING_INCLUDED_TOOL_CALLS: number;
|
|
91
|
+
PRICING_TOOL_CALL_PER_M_USD: number;
|
|
92
|
+
PRICING_TOOL_CALL_HARD_CAP: number;
|
|
88
93
|
PRICING_CUSTOM_DOMAIN_USD: number;
|
|
89
94
|
PLAN_FEATURE_ORGANIZATION: "organization";
|
|
90
95
|
PLAN_FEATURE_PROJECT: "project";
|
|
@@ -98,10 +103,17 @@ export declare const constants: {
|
|
|
98
103
|
PLAN_FEATURE_RAW_STORAGE: "rawStorage";
|
|
99
104
|
PLAN_FEATURE_EMBEDDED_STORAGE: "embeddedStorage";
|
|
100
105
|
PLAN_FEATURE_MESSAGE: "message";
|
|
106
|
+
PLAN_FEATURE_TOOL_CALL: "toolCall";
|
|
101
107
|
PLAN_LIMIT_ERROR_CODE: string;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
BILLING_METER_MESSAGES: string;
|
|
109
|
+
BILLING_METER_SHARED_MESSAGES: string;
|
|
110
|
+
BILLING_METER_EMBEDDED: string;
|
|
111
|
+
BILLING_METER_TOOL_CALLS: string;
|
|
112
|
+
BILLING_METER_UNITS_KEY: string;
|
|
113
|
+
POLAR_API_BASE: string;
|
|
114
|
+
POLAR_SANDBOX_API_BASE: string;
|
|
115
|
+
POLAR_SERVER_SANDBOX: "sandbox";
|
|
116
|
+
POLAR_SERVER_PRODUCTION: "production";
|
|
105
117
|
CONSENT_DOCUMENT_TERMS: "terms";
|
|
106
118
|
CONSENT_DOCUMENT_PRIVACY: "privacy";
|
|
107
119
|
CONSENT_DOCUMENTS: ("terms" | "privacy")[];
|
|
@@ -120,6 +132,15 @@ export declare const constants: {
|
|
|
120
132
|
CRON_HOURLY: string;
|
|
121
133
|
CRON_ERROR_ALERTS: string;
|
|
122
134
|
ALERT_STATE_KEY_ERROR_LOG: string;
|
|
135
|
+
ALERT_STATE_KEY_TOOL_CALLS: string;
|
|
136
|
+
ALERT_TOOL_CALL_SURGE: number;
|
|
137
|
+
ALERT_TOOL_CALL_CAP_FRACTION: number;
|
|
138
|
+
ALERT_TOOL_CALL_COOLDOWN_HOURS: number;
|
|
139
|
+
ALERT_TOOL_CALL_MAX_ROWS: number;
|
|
140
|
+
CONTAINMENT_TOKEN_VERSION: string;
|
|
141
|
+
CONTAINMENT_PURPOSE_DISABLE_CUSTOM_CODE: string;
|
|
142
|
+
CONTAINMENT_TOKEN_TTL_MS: number;
|
|
143
|
+
CONTAINMENT_PATH: string;
|
|
123
144
|
ALERT_MIN_STATUS: number;
|
|
124
145
|
ALERT_MAX_ROWS: number;
|
|
125
146
|
ALERT_MAX_GROUPS: number;
|
|
@@ -341,6 +362,9 @@ export declare const constants: {
|
|
|
341
362
|
model: string;
|
|
342
363
|
label: string;
|
|
343
364
|
}[];
|
|
365
|
+
LLM_CATALOG_CUSTOM_KEY: string;
|
|
366
|
+
LLM_BASE_URL_REQUIRED_MESSAGE: string;
|
|
367
|
+
LLM_BASE_URL_INVALID_MESSAGE: string;
|
|
344
368
|
LLM_SYSTEM_DEFAULT: string;
|
|
345
369
|
MAX_TOOL_LOOPS: number;
|
|
346
370
|
CHANNEL_HISTORY_LIMIT: number;
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA46DnE,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -496,8 +496,8 @@ const DEFAULT_LLM_SYSTEM_PROMPT = 'You are a helpful assistant. Answer the user
|
|
|
496
496
|
const LLM_CATALOG = [
|
|
497
497
|
{
|
|
498
498
|
provider: LLM_PROVIDER_GOOGLE,
|
|
499
|
-
model: 'gemini-3-flash
|
|
500
|
-
label: 'Gemini 3 Flash'
|
|
499
|
+
model: 'gemini-3.8-flash',
|
|
500
|
+
label: 'Gemini 3.8 Flash'
|
|
501
501
|
},
|
|
502
502
|
{
|
|
503
503
|
provider: LLM_PROVIDER_GOOGLE,
|
|
@@ -506,13 +506,13 @@ const LLM_CATALOG = [
|
|
|
506
506
|
},
|
|
507
507
|
{
|
|
508
508
|
provider: LLM_PROVIDER_OPENAI,
|
|
509
|
-
model: 'gpt-
|
|
510
|
-
label: 'GPT-
|
|
509
|
+
model: 'gpt-5.4-mini',
|
|
510
|
+
label: 'GPT-5.4 mini'
|
|
511
511
|
},
|
|
512
512
|
{
|
|
513
513
|
provider: LLM_PROVIDER_OPENAI,
|
|
514
|
-
model: 'gpt-
|
|
515
|
-
label: 'GPT-
|
|
514
|
+
model: 'gpt-5.5',
|
|
515
|
+
label: 'GPT-5.5'
|
|
516
516
|
},
|
|
517
517
|
{
|
|
518
518
|
provider: LLM_PROVIDER_ANTHROPIC,
|
|
@@ -521,15 +521,30 @@ const LLM_CATALOG = [
|
|
|
521
521
|
},
|
|
522
522
|
{
|
|
523
523
|
provider: LLM_PROVIDER_ANTHROPIC,
|
|
524
|
-
model: 'claude-sonnet-
|
|
525
|
-
label: 'Claude Sonnet
|
|
524
|
+
model: 'claude-sonnet-5',
|
|
525
|
+
label: 'Claude Sonnet 5'
|
|
526
526
|
},
|
|
527
527
|
{
|
|
528
528
|
provider: LLM_PROVIDER_ANTHROPIC,
|
|
529
|
-
model: 'claude-opus-
|
|
530
|
-
label: 'Claude
|
|
529
|
+
model: 'claude-opus-5',
|
|
530
|
+
label: 'Claude Opus 5'
|
|
531
531
|
}
|
|
532
532
|
];
|
|
533
|
+
// The picker's escape hatch. Anything that speaks the OpenAI chat-completions
|
|
534
|
+
// protocol — a gateway, an aggregator, a self-hosted server — is reachable
|
|
535
|
+
// without a catalog row: the customer supplies the model id and the base URL,
|
|
536
|
+
// and the request goes out through the OpenAI adapter. Not a provider value, so
|
|
537
|
+
// it can never reach the database; the dashboard translates it into
|
|
538
|
+
// LLM_PROVIDER_OPENAI_COMPATIBLE on submit.
|
|
539
|
+
const LLM_CATALOG_CUSTOM_KEY = 'custom';
|
|
540
|
+
// Validation messages for an organization LLM's base URL. Constants rather than
|
|
541
|
+
// inline strings because localizeZodIssue keys its translations on the exact
|
|
542
|
+
// English text, so the two files have to name the same value. Both also carry a
|
|
543
|
+
// word matchStatus recognises ("required", "must be"): the update path re-checks
|
|
544
|
+
// the merged row and throws the message as a plain Error, and anything
|
|
545
|
+
// unrecognised there becomes an opaque 500 instead of a 400.
|
|
546
|
+
const LLM_BASE_URL_REQUIRED_MESSAGE = 'A base URL is required for an OpenAI-compatible model';
|
|
547
|
+
const LLM_BASE_URL_INVALID_MESSAGE = 'Base URL must be a public https:// address';
|
|
533
548
|
const LLM_SYSTEM_DEFAULT = 'SYSTEM_DEFAULT';
|
|
534
549
|
const MAX_TOOL_LOOPS = 8;
|
|
535
550
|
// How many recent messages a channel turn replays as context.
|
|
@@ -1540,7 +1555,8 @@ const PLAN_FREE = 'FREE';
|
|
|
1540
1555
|
const PLAN_PRO = 'PRO';
|
|
1541
1556
|
const PLAN_ENTERPRISE = 'ENTERPRISE';
|
|
1542
1557
|
const PLANS = [PLAN_FREE, PLAN_PRO, PLAN_ENTERPRISE];
|
|
1543
|
-
//
|
|
1558
|
+
// The provider's subscription statuses, mirrored so the webhook can store them
|
|
1559
|
+
// verbatim.
|
|
1544
1560
|
const SUBSCRIPTION_STATUS_ACTIVE = 'active';
|
|
1545
1561
|
const SUBSCRIPTION_STATUS_TRIALING = 'trialing';
|
|
1546
1562
|
const SUBSCRIPTION_STATUS_PAST_DUE = 'past_due';
|
|
@@ -1617,6 +1633,30 @@ const PRICING_SHARED_KEY_HARD_CAP = 100_000;
|
|
|
1617
1633
|
// so $2 is now roughly break-even. Raising CHUNK_TARGET_CHARS would tip it
|
|
1618
1634
|
// positive without touching this number.
|
|
1619
1635
|
const PRICING_EMBEDDED_PER_GB_USD = 2;
|
|
1636
|
+
// Custom-tool invocations included per month, and the rate beyond them.
|
|
1637
|
+
//
|
|
1638
|
+
// "Tool call" here means one dispatch into a user's own script on Workers for
|
|
1639
|
+
// Platforms — NOT a call to a shipped integration or a proxied server. Those
|
|
1640
|
+
// cost us one screened fetch from a Worker we already pay for, which is why they
|
|
1641
|
+
// stay bundled; this one runs the customer's code on our infrastructure, and is
|
|
1642
|
+
// the first cost axis a user can turn against us rather than merely consume.
|
|
1643
|
+
//
|
|
1644
|
+
// Cloudflare bills the whole chain (dispatcher → user script → outbound worker)
|
|
1645
|
+
// as ONE request and counts CPU across all three, so a call costs ~$2.30 per
|
|
1646
|
+
// million at the per-script CPU ceiling. $5/M is ~2x that, and 1,000,000 is far
|
|
1647
|
+
// past any real month: the heaviest worked customer in the cost model makes
|
|
1648
|
+
// 800,000, and a single artifact pinned at its rate limit for a full month
|
|
1649
|
+
// manages ~2.6 million.
|
|
1650
|
+
const PRICING_INCLUDED_TOOL_CALLS = 1_000_000;
|
|
1651
|
+
const PRICING_TOOL_CALL_PER_M_USD = 5;
|
|
1652
|
+
// Abuse backstop on custom-tool invocations — the compute analogue of
|
|
1653
|
+
// PRICING_SHARED_KEY_HARD_CAP, and needed for the same reason: past a point,
|
|
1654
|
+
// usage stops looking like a customer and starts looking like a runaway loop or
|
|
1655
|
+
// a stolen credential. 20x the included allowance is ~$46 of compute against
|
|
1656
|
+
// ~$95 billed, and takes eight artifacts held at their rate limit for a month to
|
|
1657
|
+
// reach. Enterprise is null — the cost model's own enterprise example makes 20
|
|
1658
|
+
// million calls a month, so a fixed ceiling there would fight a real customer.
|
|
1659
|
+
const PRICING_TOOL_CALL_HARD_CAP = 20_000_000;
|
|
1620
1660
|
const PRICING_CUSTOM_DOMAIN_USD = 15;
|
|
1621
1661
|
const PLAN_LIMITS = {
|
|
1622
1662
|
FREE: {
|
|
@@ -1642,6 +1682,15 @@ const PLAN_LIMITS = {
|
|
|
1642
1682
|
canUseCustomLlm: false,
|
|
1643
1683
|
canUseCustomCode: false,
|
|
1644
1684
|
maxHttpEndpointsPerArtifact: 3,
|
|
1685
|
+
// Free can't deploy custom code, so the only way to have a running script on
|
|
1686
|
+
// this plan is to have DOWNGRADED with one already published — a paid org
|
|
1687
|
+
// keeps its versions and their bundles. Those tools go on serving, because
|
|
1688
|
+
// killing a customer's live integrations the moment a card fails is a worse
|
|
1689
|
+
// failure than serving a bounded number of calls while they fix it. This is
|
|
1690
|
+
// that bound: real breathing room, ~$0.02 of compute, and no overage path
|
|
1691
|
+
// off Free to turn it into a bill.
|
|
1692
|
+
includedToolCalls: 0,
|
|
1693
|
+
toolCallHardCap: 10_000,
|
|
1645
1694
|
includedMessages: 100,
|
|
1646
1695
|
includedEmbeddedBytes: 5 * MB
|
|
1647
1696
|
},
|
|
@@ -1663,6 +1712,8 @@ const PLAN_LIMITS = {
|
|
|
1663
1712
|
canUseCustomLlm: true,
|
|
1664
1713
|
canUseCustomCode: true,
|
|
1665
1714
|
maxHttpEndpointsPerArtifact: null,
|
|
1715
|
+
includedToolCalls: PRICING_INCLUDED_TOOL_CALLS,
|
|
1716
|
+
toolCallHardCap: PRICING_TOOL_CALL_HARD_CAP,
|
|
1666
1717
|
includedMessages: PRICING_INCLUDED_MESSAGES,
|
|
1667
1718
|
includedEmbeddedBytes: PRICING_INCLUDED_EMBEDDED_GB * GB
|
|
1668
1719
|
},
|
|
@@ -1680,6 +1731,12 @@ const PLAN_LIMITS = {
|
|
|
1680
1731
|
canUseCustomLlm: true,
|
|
1681
1732
|
canUseCustomCode: true,
|
|
1682
1733
|
maxHttpEndpointsPerArtifact: null,
|
|
1734
|
+
includedToolCalls: PRICING_INCLUDED_TOOL_CALLS,
|
|
1735
|
+
// No backstop: an Enterprise contract is negotiated against real volume, and
|
|
1736
|
+
// the reference deal in the cost model runs 20 million calls a month — the
|
|
1737
|
+
// exact number a Pro-shaped ceiling would refuse. Raise the ceiling by
|
|
1738
|
+
// contract; don't make one plan's abuse limit another plan's product limit.
|
|
1739
|
+
toolCallHardCap: null,
|
|
1683
1740
|
includedMessages: PRICING_INCLUDED_MESSAGES,
|
|
1684
1741
|
includedEmbeddedBytes: PRICING_INCLUDED_EMBEDDED_GB * GB
|
|
1685
1742
|
}
|
|
@@ -1698,19 +1755,42 @@ const PLAN_FEATURE_HTTP_ENDPOINT = 'httpEndpoint';
|
|
|
1698
1755
|
const PLAN_FEATURE_RAW_STORAGE = 'rawStorage';
|
|
1699
1756
|
const PLAN_FEATURE_EMBEDDED_STORAGE = 'embeddedStorage';
|
|
1700
1757
|
const PLAN_FEATURE_MESSAGE = 'message';
|
|
1758
|
+
const PLAN_FEATURE_TOOL_CALL = 'toolCall';
|
|
1701
1759
|
// Stable code returned on a quota block so clients can branch on it (402).
|
|
1702
1760
|
const PLAN_LIMIT_ERROR_CODE = 'PLAN_LIMIT_EXCEEDED';
|
|
1703
|
-
//
|
|
1704
|
-
//
|
|
1705
|
-
//
|
|
1706
|
-
//
|
|
1761
|
+
// Billing meter event names. The metering cron reports per-period OVERAGE
|
|
1762
|
+
// (usage above the plan's included allowance) to these meters; the meters'
|
|
1763
|
+
// prices on the subscribed product turn that into charges. Embedded storage is
|
|
1764
|
+
// reported in whole MB, messages as a raw count.
|
|
1765
|
+
//
|
|
1766
|
+
// Each name must match the filter on its meter exactly. A mismatch is not an
|
|
1767
|
+
// error at either end — the event is accepted, matches no meter, and the usage
|
|
1768
|
+
// is silently unbilled.
|
|
1707
1769
|
//
|
|
1708
1770
|
// Messages report to two separate meters because the two kinds of turn bill at
|
|
1709
1771
|
// different rates — a turn on the org's own key is a platform fee, a turn on our
|
|
1710
1772
|
// model is inference we bought. One meter can't price both.
|
|
1711
|
-
const
|
|
1712
|
-
const
|
|
1713
|
-
const
|
|
1773
|
+
const BILLING_METER_MESSAGES = 'ganju_channel_messages';
|
|
1774
|
+
const BILLING_METER_SHARED_MESSAGES = 'ganju_shared_messages';
|
|
1775
|
+
const BILLING_METER_EMBEDDED = 'ganju_embedded_storage';
|
|
1776
|
+
// Custom-tool invocations, reported as a raw count of the calls above the
|
|
1777
|
+
// included allowance and priced per call at $5/1,000,000. Metered prices are
|
|
1778
|
+
// per single unit, so a partial block is billed as the fraction it is — a
|
|
1779
|
+
// customer 2.5 million past the allowance owes $12.50, which is what every page
|
|
1780
|
+
// of ours quotes.
|
|
1781
|
+
const BILLING_METER_TOOL_CALLS = 'ganju_custom_tool_calls';
|
|
1782
|
+
// The metadata property every meter aggregates (`sum` over it). Ingested events
|
|
1783
|
+
// carry the increment under this key, so it has to agree with the aggregation
|
|
1784
|
+
// configured on all four meters — which is why it lives beside their names
|
|
1785
|
+
// rather than at the call site.
|
|
1786
|
+
const BILLING_METER_UNITS_KEY = 'units';
|
|
1787
|
+
// Polar API hosts. Sandbox is a separate host rather than a mode flag, so the
|
|
1788
|
+
// account, products, meters and webhook secret there are all distinct from
|
|
1789
|
+
// production's — which is what `POLAR_SERVER` selects between.
|
|
1790
|
+
const POLAR_API_BASE = 'https://api.polar.sh';
|
|
1791
|
+
const POLAR_SANDBOX_API_BASE = 'https://sandbox-api.polar.sh';
|
|
1792
|
+
const POLAR_SERVER_SANDBOX = 'sandbox';
|
|
1793
|
+
const POLAR_SERVER_PRODUCTION = 'production';
|
|
1714
1794
|
// Legal documents a user accepts, and the version they're on. Bump the version
|
|
1715
1795
|
// when the document changes materially — existing users are then re-prompted,
|
|
1716
1796
|
// and the old acceptance stays on record. Keep in sync with the "Last updated"
|
|
@@ -1718,7 +1798,7 @@ const STRIPE_METER_EMBEDDED = 'ganju_embedded_storage';
|
|
|
1718
1798
|
const CONSENT_DOCUMENT_TERMS = 'terms';
|
|
1719
1799
|
const CONSENT_DOCUMENT_PRIVACY = 'privacy';
|
|
1720
1800
|
const CONSENT_DOCUMENTS = [CONSENT_DOCUMENT_TERMS, CONSENT_DOCUMENT_PRIVACY];
|
|
1721
|
-
const CONSENT_CURRENT_VERSION = '2026-
|
|
1801
|
+
const CONSENT_CURRENT_VERSION = '2026-09-10';
|
|
1722
1802
|
const CONSENT_SOURCE_SIGNUP = 'signup';
|
|
1723
1803
|
const CONSENT_SOURCE_REACCEPT = 'reaccept';
|
|
1724
1804
|
const CONSENT_SOURCES = [CONSENT_SOURCE_SIGNUP, CONSENT_SOURCE_REACCEPT];
|
|
@@ -1753,6 +1833,39 @@ const RETENTION_EXPIRED_SESSION_DAYS = 30;
|
|
|
1753
1833
|
const CRON_HOURLY = '0 * * * *';
|
|
1754
1834
|
const CRON_ERROR_ALERTS = '*/15 * * * *';
|
|
1755
1835
|
const ALERT_STATE_KEY_ERROR_LOG = 'error_log';
|
|
1836
|
+
// Custom-tool usage alerting, keyed per organization as `tool_calls:<id>`. The
|
|
1837
|
+
// monthly hard cap bounds what abuse can spend; these thresholds are what say
|
|
1838
|
+
// something is happening NOW, while there is still a month left to spend.
|
|
1839
|
+
const ALERT_STATE_KEY_TOOL_CALLS = 'tool_calls';
|
|
1840
|
+
// Calls in a single hour. The per-tool rate limit allows 3,600/hour, and a month
|
|
1841
|
+
// of the included million sustained is ~1,370/hour — so five figures in one hour
|
|
1842
|
+
// is either many artifacts at full tilt or something that should be looked at.
|
|
1843
|
+
const ALERT_TOOL_CALL_SURGE = 10_000;
|
|
1844
|
+
// The share of the abuse backstop at which the wall is close enough to warn
|
|
1845
|
+
// about. Half a month's ceiling reached is worth an email even if the rate is
|
|
1846
|
+
// unremarkable, because the alternative is a customer meeting it silently.
|
|
1847
|
+
const ALERT_TOOL_CALL_CAP_FRACTION = 0.5;
|
|
1848
|
+
// How long to stay quiet about one organization after alerting on it. Without
|
|
1849
|
+
// this a busy month is an hourly email, and an hourly email is a muted one.
|
|
1850
|
+
const ALERT_TOOL_CALL_COOLDOWN_HOURS = 6;
|
|
1851
|
+
// Organizations itemised in one digest.
|
|
1852
|
+
const ALERT_TOOL_CALL_MAX_ROWS = 25;
|
|
1853
|
+
// The "stop these tools" link the usage digest carries.
|
|
1854
|
+
//
|
|
1855
|
+
// It exists because the alert travels and the response did not: every other
|
|
1856
|
+
// containment step needs a shell holding the production database URL, so an
|
|
1857
|
+
// abuse notice arriving away from a desk was one nobody could act on for hours.
|
|
1858
|
+
//
|
|
1859
|
+
// Narrow on purpose. It disables the organization's custom-code installs — the
|
|
1860
|
+
// tools stop registering at boot, the code, versions and settings all survive,
|
|
1861
|
+
// and any owner can switch them back on. It cannot delete a script, touch a
|
|
1862
|
+
// credential, or reach anything else.
|
|
1863
|
+
const CONTAINMENT_TOKEN_VERSION = '1';
|
|
1864
|
+
const CONTAINMENT_PURPOSE_DISABLE_CUSTOM_CODE = 'disable-custom-code';
|
|
1865
|
+
// Long enough to still work when the mail is read a few hours late, short enough
|
|
1866
|
+
// that a forwarded thread or an archived inbox is not a way in.
|
|
1867
|
+
const CONTAINMENT_TOKEN_TTL_MS = 12 * 60 * 60 * 1000;
|
|
1868
|
+
const CONTAINMENT_PATH = '/containment';
|
|
1756
1869
|
// Only alert on genuine server failures. 4xx rows are expected client errors
|
|
1757
1870
|
// (validation, not-found, quota) and would drown the signal.
|
|
1758
1871
|
const ALERT_MIN_STATUS = 500;
|
|
@@ -1793,6 +1906,9 @@ exports.constants = {
|
|
|
1793
1906
|
PRICING_INCLUDED_EMBEDDED_GB,
|
|
1794
1907
|
PRICING_MESSAGE_PER_1K_USD,
|
|
1795
1908
|
PRICING_EMBEDDED_PER_GB_USD,
|
|
1909
|
+
PRICING_INCLUDED_TOOL_CALLS,
|
|
1910
|
+
PRICING_TOOL_CALL_PER_M_USD,
|
|
1911
|
+
PRICING_TOOL_CALL_HARD_CAP,
|
|
1796
1912
|
PRICING_CUSTOM_DOMAIN_USD,
|
|
1797
1913
|
PLAN_FEATURE_ORGANIZATION,
|
|
1798
1914
|
PLAN_FEATURE_PROJECT,
|
|
@@ -1806,10 +1922,17 @@ exports.constants = {
|
|
|
1806
1922
|
PLAN_FEATURE_RAW_STORAGE,
|
|
1807
1923
|
PLAN_FEATURE_EMBEDDED_STORAGE,
|
|
1808
1924
|
PLAN_FEATURE_MESSAGE,
|
|
1925
|
+
PLAN_FEATURE_TOOL_CALL,
|
|
1809
1926
|
PLAN_LIMIT_ERROR_CODE,
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1927
|
+
BILLING_METER_MESSAGES,
|
|
1928
|
+
BILLING_METER_SHARED_MESSAGES,
|
|
1929
|
+
BILLING_METER_EMBEDDED,
|
|
1930
|
+
BILLING_METER_TOOL_CALLS,
|
|
1931
|
+
BILLING_METER_UNITS_KEY,
|
|
1932
|
+
POLAR_API_BASE,
|
|
1933
|
+
POLAR_SANDBOX_API_BASE,
|
|
1934
|
+
POLAR_SERVER_SANDBOX,
|
|
1935
|
+
POLAR_SERVER_PRODUCTION,
|
|
1813
1936
|
CONSENT_DOCUMENT_TERMS,
|
|
1814
1937
|
CONSENT_DOCUMENT_PRIVACY,
|
|
1815
1938
|
CONSENT_DOCUMENTS,
|
|
@@ -1823,6 +1946,15 @@ exports.constants = {
|
|
|
1823
1946
|
CRON_HOURLY,
|
|
1824
1947
|
CRON_ERROR_ALERTS,
|
|
1825
1948
|
ALERT_STATE_KEY_ERROR_LOG,
|
|
1949
|
+
ALERT_STATE_KEY_TOOL_CALLS,
|
|
1950
|
+
ALERT_TOOL_CALL_SURGE,
|
|
1951
|
+
ALERT_TOOL_CALL_CAP_FRACTION,
|
|
1952
|
+
ALERT_TOOL_CALL_COOLDOWN_HOURS,
|
|
1953
|
+
ALERT_TOOL_CALL_MAX_ROWS,
|
|
1954
|
+
CONTAINMENT_TOKEN_VERSION,
|
|
1955
|
+
CONTAINMENT_PURPOSE_DISABLE_CUSTOM_CODE,
|
|
1956
|
+
CONTAINMENT_TOKEN_TTL_MS,
|
|
1957
|
+
CONTAINMENT_PATH,
|
|
1826
1958
|
ALERT_MIN_STATUS,
|
|
1827
1959
|
ALERT_MAX_ROWS,
|
|
1828
1960
|
ALERT_MAX_GROUPS,
|
|
@@ -2034,6 +2166,9 @@ exports.constants = {
|
|
|
2034
2166
|
DEFAULT_LLM_MODEL,
|
|
2035
2167
|
DEFAULT_LLM_SYSTEM_PROMPT,
|
|
2036
2168
|
LLM_CATALOG,
|
|
2169
|
+
LLM_CATALOG_CUSTOM_KEY,
|
|
2170
|
+
LLM_BASE_URL_REQUIRED_MESSAGE,
|
|
2171
|
+
LLM_BASE_URL_INVALID_MESSAGE,
|
|
2037
2172
|
LLM_SYSTEM_DEFAULT,
|
|
2038
2173
|
MAX_TOOL_LOOPS,
|
|
2039
2174
|
CHANNEL_HISTORY_LIMIT,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface ContainmentTokenPayload {
|
|
2
|
+
v: string;
|
|
3
|
+
p: string;
|
|
4
|
+
organizationId: string;
|
|
5
|
+
iat: number;
|
|
6
|
+
exp: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Mint a containment link token for one organization.
|
|
10
|
+
*
|
|
11
|
+
* The lifetime is deliberately short. This is not a login: it is a thing you act
|
|
12
|
+
* on while reading the mail that carried it, and an expiry measured in hours
|
|
13
|
+
* means a forwarded thread or an archived inbox stops being a way in.
|
|
14
|
+
*/
|
|
15
|
+
export declare const mintContainmentToken: (organizationId: string, secret: string, issuedAt?: number, ttlMs?: number) => Promise<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Verify a containment token and return its payload, or null when it is
|
|
18
|
+
* malformed, expired, of an unknown format version, minted for another purpose,
|
|
19
|
+
* or not signed by this deployment's secret.
|
|
20
|
+
*
|
|
21
|
+
* Null rather than a reason, so the page can answer every rejection identically:
|
|
22
|
+
* a link that says *why* it failed tells whoever found it what to change.
|
|
23
|
+
*/
|
|
24
|
+
export declare const verifyContainmentToken: (token: string, secret: string, now?: number) => Promise<ContainmentTokenPayload | null>;
|
|
25
|
+
//# sourceMappingURL=containmentToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"containmentToken.d.ts","sourceRoot":"","sources":["../src/containmentToken.ts"],"names":[],"mappings":"AA4BA,MAAM,WAAW,uBAAuB;IAGtC,CAAC,EAAE,MAAM,CAAC;IAEV,CAAC,EAAE,MAAM,CAAC;IACV,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAaD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,gBAAgB,MAAM,EACtB,QAAQ,MAAM,EACd,WAAU,MAAmB,EAC7B,QAAO,MAA2C,KACjD,OAAO,CAAC,MAAM,CAoBhB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GACjC,OAAO,MAAM,EACb,QAAQ,MAAM,EACd,MAAK,MAAmB,KACvB,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAiDxC,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyContainmentToken = exports.mintContainmentToken = void 0;
|
|
4
|
+
const base64_1 = require("./base64");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const encoder = new TextEncoder();
|
|
7
|
+
const importKey = (secret) => crypto.subtle.importKey('raw', encoder.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign', 'verify']);
|
|
8
|
+
/**
|
|
9
|
+
* Mint a containment link token for one organization.
|
|
10
|
+
*
|
|
11
|
+
* The lifetime is deliberately short. This is not a login: it is a thing you act
|
|
12
|
+
* on while reading the mail that carried it, and an expiry measured in hours
|
|
13
|
+
* means a forwarded thread or an archived inbox stops being a way in.
|
|
14
|
+
*/
|
|
15
|
+
const mintContainmentToken = async (organizationId, secret, issuedAt = Date.now(), ttlMs = constants_1.constants.CONTAINMENT_TOKEN_TTL_MS) => {
|
|
16
|
+
const body = {
|
|
17
|
+
v: constants_1.constants.CONTAINMENT_TOKEN_VERSION,
|
|
18
|
+
p: constants_1.constants.CONTAINMENT_PURPOSE_DISABLE_CUSTOM_CODE,
|
|
19
|
+
organizationId,
|
|
20
|
+
iat: Math.floor(issuedAt / 1000),
|
|
21
|
+
// Rounded up so a stated lifetime is a floor rather than up to a second
|
|
22
|
+
// short of one.
|
|
23
|
+
exp: Math.ceil((issuedAt + ttlMs) / 1000)
|
|
24
|
+
};
|
|
25
|
+
const encodedPayload = (0, base64_1.toBase64Url)((0, base64_1.bytesToBase64)(encoder.encode(JSON.stringify(body))));
|
|
26
|
+
const key = await importKey(secret);
|
|
27
|
+
const signature = await crypto.subtle.sign('HMAC', key, encoder.encode(encodedPayload));
|
|
28
|
+
return `${encodedPayload}.${(0, base64_1.toBase64Url)((0, base64_1.bytesToBase64)(new Uint8Array(signature)))}`;
|
|
29
|
+
};
|
|
30
|
+
exports.mintContainmentToken = mintContainmentToken;
|
|
31
|
+
/**
|
|
32
|
+
* Verify a containment token and return its payload, or null when it is
|
|
33
|
+
* malformed, expired, of an unknown format version, minted for another purpose,
|
|
34
|
+
* or not signed by this deployment's secret.
|
|
35
|
+
*
|
|
36
|
+
* Null rather than a reason, so the page can answer every rejection identically:
|
|
37
|
+
* a link that says *why* it failed tells whoever found it what to change.
|
|
38
|
+
*/
|
|
39
|
+
const verifyContainmentToken = async (token, secret, now = Date.now()) => {
|
|
40
|
+
const separator = token.lastIndexOf('.');
|
|
41
|
+
if (separator <= 0)
|
|
42
|
+
return null;
|
|
43
|
+
const encodedPayload = token.slice(0, separator);
|
|
44
|
+
const signature = token.slice(separator + 1);
|
|
45
|
+
const key = await importKey(secret);
|
|
46
|
+
let valid;
|
|
47
|
+
try {
|
|
48
|
+
const signatureBytes = new Uint8Array((0, base64_1.base64ToBytes)((0, base64_1.fromBase64Url)(signature)));
|
|
49
|
+
valid = await crypto.subtle.verify('HMAC', key, signatureBytes, encoder.encode(encodedPayload));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
if (!valid)
|
|
55
|
+
return null;
|
|
56
|
+
let parsed;
|
|
57
|
+
try {
|
|
58
|
+
parsed = JSON.parse(new TextDecoder().decode((0, base64_1.base64ToBytes)((0, base64_1.fromBase64Url)(encodedPayload))));
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
if (!parsed || typeof parsed !== 'object')
|
|
64
|
+
return null;
|
|
65
|
+
const candidate = parsed;
|
|
66
|
+
if (candidate.v !== constants_1.constants.CONTAINMENT_TOKEN_VERSION)
|
|
67
|
+
return null;
|
|
68
|
+
if (candidate.p !== constants_1.constants.CONTAINMENT_PURPOSE_DISABLE_CUSTOM_CODE) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
if (typeof candidate.organizationId !== 'string' ||
|
|
72
|
+
!candidate.organizationId) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
if (typeof candidate.exp !== 'number')
|
|
76
|
+
return null;
|
|
77
|
+
if (candidate.exp * 1000 <= now)
|
|
78
|
+
return null;
|
|
79
|
+
return candidate;
|
|
80
|
+
};
|
|
81
|
+
exports.verifyContainmentToken = verifyContainmentToken;
|
package/dist/crypto.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAU/B,eAAO,MAAM,0BAA0B,GAAI,GAAG,OAAO,WAMpD,CAAC;AAYF,eAAO,MAAM,aAAa,GAAI,WAAW,MAAM,EAAE,QAAQ,MAAM,WAS9D,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,WAS1D,CAAC;AAEF,eAAO,MAAM,SAAS,GAAU,OAAO,MAAM,oBAW5C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAU,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAU/B,eAAO,MAAM,0BAA0B,GAAI,GAAG,OAAO,WAMpD,CAAC;AAYF,eAAO,MAAM,aAAa,GAAI,WAAW,MAAM,EAAE,QAAQ,MAAM,WAS9D,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,WAS1D,CAAC;AAEF,eAAO,MAAM,SAAS,GAAU,OAAO,MAAM,oBAW5C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAU,OAAO,MAAM,oBAalD,CAAC;AAEF,eAAO,MAAM,aAAa,GAAU,KAAK,MAAM,EAAE,SAAS,MAAM,oBAmB/D,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,YAOnD,CAAC"}
|
package/dist/crypto.js
CHANGED
|
@@ -67,7 +67,10 @@ const sha256Base64Url = async (input) => {
|
|
|
67
67
|
let binary = '';
|
|
68
68
|
for (let i = 0; i < bytes.length; i++)
|
|
69
69
|
binary += String.fromCharCode(bytes[i]);
|
|
70
|
-
return btoa(binary)
|
|
70
|
+
return btoa(binary)
|
|
71
|
+
.replace(/\+/g, '-')
|
|
72
|
+
.replace(/\//g, '_')
|
|
73
|
+
.replace(/=+$/, '');
|
|
71
74
|
};
|
|
72
75
|
exports.sha256Base64Url = sha256Base64Url;
|
|
73
76
|
const hmacSha256Hex = async (key, message) => {
|
package/dist/getEnv.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEnv.d.ts","sourceRoot":"","sources":["../src/getEnv.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;CACzC;AAED,eAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"getEnv.d.ts","sourceRoot":"","sources":["../src/getEnv.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;CACzC;AAED,eAAO,MAAM,MAAM,GAAI,QAAQ,SAAS,EAAE,KAAK,MAAM,KAAG,MAAM,GAAG,SAKhE,CAAC"}
|