@shushed/helpers 0.0.23 → 0.0.25
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.d.ts +154 -5
- package/dist/index.js +110 -20
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -28715,19 +28715,20 @@ declare class Runtime {
|
|
|
28715
28715
|
constructor(opts: Opts);
|
|
28716
28716
|
}
|
|
28717
28717
|
|
|
28718
|
+
type Level = 'env' | 'workflow' | 'trigger';
|
|
28718
28719
|
declare class EnvEngine extends Runtime {
|
|
28719
|
-
docRef: DocumentReference
|
|
28720
|
+
docRef: Record<Level, DocumentReference>;
|
|
28720
28721
|
private store;
|
|
28721
28722
|
constructor(opts: Opts, firestore: Firestore);
|
|
28722
28723
|
set(envs: Array<{
|
|
28723
28724
|
name: string;
|
|
28724
28725
|
value: string;
|
|
28725
|
-
}
|
|
28726
|
+
}>, level?: Level, encryptWithValue?: string): Promise<undefined>;
|
|
28726
28727
|
private initializeIfNeeded;
|
|
28727
|
-
get<T extends ReadonlyArray<string>>(keys: T): Promise<{
|
|
28728
|
+
get<T extends ReadonlyArray<string>>(keys: T, level?: Level, decryptWithValue?: string): Promise<{
|
|
28728
28729
|
[K in T[number]]: string;
|
|
28729
28730
|
}>;
|
|
28730
|
-
get(key: string): Promise<string>;
|
|
28731
|
+
get(key: string, level?: Level, decryptWithValue?: string): Promise<string>;
|
|
28731
28732
|
}
|
|
28732
28733
|
|
|
28733
28734
|
declare class PubSubHelper extends Runtime {
|
|
@@ -28832,6 +28833,152 @@ declare const validateGoogleAuth: (opts: Opts & {
|
|
|
28832
28833
|
serviceAccount?: string | null;
|
|
28833
28834
|
}, headers: Record<string, string>, firestore: Firestore) => Promise<void>;
|
|
28834
28835
|
|
|
28836
|
+
type TriggerOnExecuteOptions = {
|
|
28837
|
+
req: {
|
|
28838
|
+
status?: number;
|
|
28839
|
+
body?: string;
|
|
28840
|
+
throw: (status: number, body: string) => void;
|
|
28841
|
+
};
|
|
28842
|
+
request: {
|
|
28843
|
+
headers: Record<string, string>;
|
|
28844
|
+
method: 'POST' | 'GET' | 'PUT' | 'PATCH';
|
|
28845
|
+
body: undefined;
|
|
28846
|
+
path: string;
|
|
28847
|
+
query: Record<string, string>;
|
|
28848
|
+
host: string;
|
|
28849
|
+
hostname: string;
|
|
28850
|
+
originalUrl: string;
|
|
28851
|
+
ip: string;
|
|
28852
|
+
ips: [];
|
|
28853
|
+
querystring: string;
|
|
28854
|
+
subdomains: Array<string>;
|
|
28855
|
+
secure: boolean;
|
|
28856
|
+
protocol: 'http' | 'https';
|
|
28857
|
+
params: undefined;
|
|
28858
|
+
};
|
|
28859
|
+
nodeReq: Request;
|
|
28860
|
+
state: Record<string, string>;
|
|
28861
|
+
root: {
|
|
28862
|
+
state: Record<string, string>;
|
|
28863
|
+
};
|
|
28864
|
+
workflowExecutionId: string;
|
|
28865
|
+
logging: {
|
|
28866
|
+
log: (...x: Array<any>) => void;
|
|
28867
|
+
warn: (...x: Array<any>) => void;
|
|
28868
|
+
error: (...x: Array<any>) => void;
|
|
28869
|
+
};
|
|
28870
|
+
terminate: (status: number, message: string) => void;
|
|
28871
|
+
env: {
|
|
28872
|
+
set: (args: {
|
|
28873
|
+
name: string;
|
|
28874
|
+
value: string;
|
|
28875
|
+
}[], level: 'workflow' | 'project') => Promise<void>;
|
|
28876
|
+
get: (name: string, level: 'workflow' | 'project') => string | null;
|
|
28877
|
+
triggerEnv: any;
|
|
28878
|
+
workflowId: string;
|
|
28879
|
+
};
|
|
28880
|
+
auth: {
|
|
28881
|
+
getToken: (forceRefresh: boolean) => any;
|
|
28882
|
+
getKey: (options: {
|
|
28883
|
+
ignoreMissingKey?: boolean;
|
|
28884
|
+
}) => any;
|
|
28885
|
+
};
|
|
28886
|
+
getBuildShipFile: (x: any) => any;
|
|
28887
|
+
trigger: {
|
|
28888
|
+
meta: {
|
|
28889
|
+
fileUploadLimit: boolean;
|
|
28890
|
+
name: string;
|
|
28891
|
+
description: string;
|
|
28892
|
+
id: string;
|
|
28893
|
+
payloadLimit: boolean;
|
|
28894
|
+
icon: {
|
|
28895
|
+
type: 'SVG';
|
|
28896
|
+
};
|
|
28897
|
+
};
|
|
28898
|
+
script: string;
|
|
28899
|
+
defaultValues: {
|
|
28900
|
+
path: string;
|
|
28901
|
+
inputs: string;
|
|
28902
|
+
};
|
|
28903
|
+
lifeCycleFunctions: Array<'onExecution' | 'onCreate' | 'onResponse' | 'onUpdate' | 'getData'>;
|
|
28904
|
+
id: string;
|
|
28905
|
+
_libRef: {
|
|
28906
|
+
integrity: string;
|
|
28907
|
+
libNodeRefId: string;
|
|
28908
|
+
libType: string;
|
|
28909
|
+
isDirty: boolean;
|
|
28910
|
+
version: string;
|
|
28911
|
+
src: string;
|
|
28912
|
+
};
|
|
28913
|
+
label: string;
|
|
28914
|
+
description: string;
|
|
28915
|
+
envs: Record<string, any>;
|
|
28916
|
+
env: any;
|
|
28917
|
+
};
|
|
28918
|
+
workflow: {
|
|
28919
|
+
id: string;
|
|
28920
|
+
};
|
|
28921
|
+
};
|
|
28922
|
+
type TriggerOnCreateOptions = {
|
|
28923
|
+
runtimeUrl: string;
|
|
28924
|
+
workflowId: string;
|
|
28925
|
+
auth: {
|
|
28926
|
+
getToken: (forceRefresh: boolean) => any;
|
|
28927
|
+
getKey: (options: {
|
|
28928
|
+
ignoreMissingKey?: boolean;
|
|
28929
|
+
}) => any;
|
|
28930
|
+
};
|
|
28931
|
+
trigger: {
|
|
28932
|
+
meta: {
|
|
28933
|
+
fileUploadLimit: boolean;
|
|
28934
|
+
name: string;
|
|
28935
|
+
description: string;
|
|
28936
|
+
id: string;
|
|
28937
|
+
payloadLimit: boolean;
|
|
28938
|
+
icon: {
|
|
28939
|
+
type: 'SVG';
|
|
28940
|
+
};
|
|
28941
|
+
};
|
|
28942
|
+
script: string;
|
|
28943
|
+
response: any;
|
|
28944
|
+
dependencies: Record<string, string>;
|
|
28945
|
+
type: string;
|
|
28946
|
+
data: any;
|
|
28947
|
+
config: any;
|
|
28948
|
+
usage: string;
|
|
28949
|
+
defaultValues: {
|
|
28950
|
+
path: string;
|
|
28951
|
+
inputs: string;
|
|
28952
|
+
};
|
|
28953
|
+
lifeCycleFunctions: Array<'onExecution' | 'onCreate' | 'onResponse' | 'onUpdate' | 'getData'>;
|
|
28954
|
+
id: string;
|
|
28955
|
+
_libRef: {
|
|
28956
|
+
integrity: string;
|
|
28957
|
+
libNodeRefId: string;
|
|
28958
|
+
libType: string;
|
|
28959
|
+
isDirty: boolean;
|
|
28960
|
+
version: string;
|
|
28961
|
+
src: string;
|
|
28962
|
+
};
|
|
28963
|
+
label: string;
|
|
28964
|
+
description: string;
|
|
28965
|
+
envs: Record<string, any>;
|
|
28966
|
+
env: any;
|
|
28967
|
+
};
|
|
28968
|
+
workflow: {
|
|
28969
|
+
id: string;
|
|
28970
|
+
};
|
|
28971
|
+
env: {
|
|
28972
|
+
set: (args: {
|
|
28973
|
+
name: string;
|
|
28974
|
+
value: string;
|
|
28975
|
+
}[], level: 'workflow' | 'project') => Promise<void>;
|
|
28976
|
+
get: (name: string, level: 'workflow' | 'project') => string | null;
|
|
28977
|
+
triggerEnv: any;
|
|
28978
|
+
workflowId: string;
|
|
28979
|
+
};
|
|
28980
|
+
};
|
|
28981
|
+
|
|
28835
28982
|
type index_EnvEngine = EnvEngine;
|
|
28836
28983
|
declare const index_EnvEngine: typeof EnvEngine;
|
|
28837
28984
|
type index_JWKSHelper = JWKSHelper;
|
|
@@ -28844,6 +28991,8 @@ type index_SchedulerHelper = SchedulerHelper;
|
|
|
28844
28991
|
declare const index_SchedulerHelper: typeof SchedulerHelper;
|
|
28845
28992
|
type index_Secrets = Secrets;
|
|
28846
28993
|
declare const index_Secrets: typeof Secrets;
|
|
28994
|
+
type index_TriggerOnCreateOptions = TriggerOnCreateOptions;
|
|
28995
|
+
type index_TriggerOnExecuteOptions = TriggerOnExecuteOptions;
|
|
28847
28996
|
declare const index_isCronMessage: typeof isCronMessage;
|
|
28848
28997
|
declare const index_isPubSubRequest: typeof isPubSubRequest;
|
|
28849
28998
|
declare const index_sanitize: typeof sanitize;
|
|
@@ -28851,7 +29000,7 @@ declare const index_sanitizeToString: typeof sanitizeToString;
|
|
|
28851
29000
|
declare const index_validate: typeof validate;
|
|
28852
29001
|
declare const index_validateGoogleAuth: typeof validateGoogleAuth;
|
|
28853
29002
|
declare namespace index {
|
|
28854
|
-
export { index_EnvEngine as EnvEngine, index_JWKSHelper as JWKSHelper, index_PubSubHelper as PubSubHelper, index_Runtime as Runtime, index_SchedulerHelper as SchedulerHelper, index_Secrets as Secrets, index_isCronMessage as isCronMessage, index_isPubSubRequest as isPubSubRequest, index_sanitize as sanitize, index_sanitizeToString as sanitizeToString, index_validate as validate, index_validateGoogleAuth as validateGoogleAuth };
|
|
29003
|
+
export { index_EnvEngine as EnvEngine, index_JWKSHelper as JWKSHelper, index_PubSubHelper as PubSubHelper, index_Runtime as Runtime, index_SchedulerHelper as SchedulerHelper, index_Secrets as Secrets, type index_TriggerOnCreateOptions as TriggerOnCreateOptions, type index_TriggerOnExecuteOptions as TriggerOnExecuteOptions, index_isCronMessage as isCronMessage, index_isPubSubRequest as isPubSubRequest, index_sanitize as sanitize, index_sanitizeToString as sanitizeToString, index_validate as validate, index_validateGoogleAuth as validateGoogleAuth };
|
|
28855
29004
|
}
|
|
28856
29005
|
|
|
28857
29006
|
export { index as lib, index$9 as schema, index$1 as types };
|
package/dist/index.js
CHANGED
|
@@ -346,6 +346,9 @@ var sanitize = new import_deep_redact.DeepRedact({
|
|
|
346
346
|
replaceStringByLength: true
|
|
347
347
|
});
|
|
348
348
|
|
|
349
|
+
// src-public/env.ts
|
|
350
|
+
var crypto = __toESM(require("crypto"));
|
|
351
|
+
|
|
349
352
|
// src-public/runtime.ts
|
|
350
353
|
var DEFAULT_BRANCH = "migratedprod";
|
|
351
354
|
var Runtime = class {
|
|
@@ -373,20 +376,39 @@ var Runtime = class {
|
|
|
373
376
|
// src-public/env.ts
|
|
374
377
|
var EnvEngine = class extends Runtime {
|
|
375
378
|
docRef;
|
|
376
|
-
store
|
|
379
|
+
store;
|
|
377
380
|
constructor(opts, firestore) {
|
|
378
381
|
super(opts);
|
|
379
|
-
this.docRef =
|
|
382
|
+
this.docRef = {
|
|
383
|
+
env: firestore?.doc(`0/0/${this.envName}`),
|
|
384
|
+
workflow: firestore?.doc(`${this.workflowId}/0/${this.envName}`),
|
|
385
|
+
trigger: firestore?.doc(`${this.workflowId}/${this.triggerId}/${this.envName}`)
|
|
386
|
+
};
|
|
387
|
+
this.store = {
|
|
388
|
+
env: null,
|
|
389
|
+
workflow: null,
|
|
390
|
+
trigger: null
|
|
391
|
+
};
|
|
380
392
|
}
|
|
381
|
-
async set(envs) {
|
|
382
|
-
await this.initializeIfNeeded();
|
|
393
|
+
async set(envs, level = "trigger", encryptWithValue) {
|
|
394
|
+
await this.initializeIfNeeded(level);
|
|
395
|
+
let aes = null;
|
|
396
|
+
if (encryptWithValue) {
|
|
397
|
+
aes = new AES256GCM(Buffer.from(encryptWithValue, "utf8"));
|
|
398
|
+
}
|
|
383
399
|
const obj = envs.filter((env) => env.name).reduce(
|
|
384
|
-
(prev, curr) =>
|
|
400
|
+
(prev, curr) => {
|
|
401
|
+
let value = curr.value;
|
|
402
|
+
if (aes) {
|
|
403
|
+
value = aes.encrypt(curr.value);
|
|
404
|
+
}
|
|
405
|
+
return { ...prev, [curr.name]: value };
|
|
406
|
+
},
|
|
385
407
|
{}
|
|
386
408
|
);
|
|
387
|
-
if (this.docRef) {
|
|
409
|
+
if (this.docRef[level]) {
|
|
388
410
|
try {
|
|
389
|
-
await this.docRef.set(
|
|
411
|
+
await this.docRef[level].set(
|
|
390
412
|
obj,
|
|
391
413
|
{ merge: true }
|
|
392
414
|
);
|
|
@@ -394,36 +416,104 @@ var EnvEngine = class extends Runtime {
|
|
|
394
416
|
throw new Error(`Failed to set the ${envs.map((x) => x.name).join(", ")}. Error: ${err.message}`);
|
|
395
417
|
}
|
|
396
418
|
}
|
|
397
|
-
Object.assign(this.store, obj);
|
|
419
|
+
Object.assign(this.store[level], obj);
|
|
398
420
|
return void 0;
|
|
399
421
|
}
|
|
400
|
-
async initializeIfNeeded() {
|
|
401
|
-
if (!this.store) {
|
|
402
|
-
if (this.docRef) {
|
|
403
|
-
const docSnapshot = await this.docRef.get();
|
|
422
|
+
async initializeIfNeeded(level = "trigger") {
|
|
423
|
+
if (!this.store[level]) {
|
|
424
|
+
if (this.docRef[level]) {
|
|
425
|
+
const docSnapshot = await this.docRef[level].get();
|
|
404
426
|
const data = docSnapshot.data();
|
|
405
|
-
this.store = {};
|
|
427
|
+
this.store[level] = {};
|
|
406
428
|
for (const k in data) {
|
|
407
429
|
const v = data[k];
|
|
408
|
-
this.store[k] = typeof v !== "string" ? `${v === null || typeof v === "undefined" ? "" : `${v}`}` : v;
|
|
430
|
+
this.store[level][k] = typeof v !== "string" ? `${v === null || typeof v === "undefined" ? "" : `${v}`}` : v;
|
|
409
431
|
}
|
|
410
432
|
} else {
|
|
411
|
-
this.store = {};
|
|
433
|
+
this.store[level] = {};
|
|
412
434
|
}
|
|
413
435
|
}
|
|
414
436
|
}
|
|
415
|
-
async get(keys) {
|
|
416
|
-
await this.initializeIfNeeded();
|
|
437
|
+
async get(keys, level = "trigger", decryptWithValue) {
|
|
438
|
+
await this.initializeIfNeeded(level);
|
|
439
|
+
let aes = null;
|
|
440
|
+
if (decryptWithValue) {
|
|
441
|
+
aes = new AES256GCM(Buffer.from(decryptWithValue, "utf8"));
|
|
442
|
+
}
|
|
417
443
|
if (typeof keys === "string") {
|
|
418
|
-
|
|
444
|
+
try {
|
|
445
|
+
if (aes) {
|
|
446
|
+
return aes.decrypt(this.store[level]?.[keys] || "");
|
|
447
|
+
}
|
|
448
|
+
} catch (err) {
|
|
449
|
+
return "";
|
|
450
|
+
}
|
|
451
|
+
return this.store[level]?.[keys] || "";
|
|
419
452
|
}
|
|
420
453
|
return keys.reduce((acc, k) => {
|
|
421
|
-
const v = this.store?.[k];
|
|
422
|
-
|
|
454
|
+
const v = this.store[level]?.[k];
|
|
455
|
+
if (aes && typeof v === "string") {
|
|
456
|
+
try {
|
|
457
|
+
acc[k] = aes.decrypt(v);
|
|
458
|
+
} catch (err) {
|
|
459
|
+
acc[k] = "";
|
|
460
|
+
}
|
|
461
|
+
} else {
|
|
462
|
+
acc[k] = typeof v !== "string" ? `${v === null || typeof v === "undefined" ? "" : `${v}`}` : v;
|
|
463
|
+
}
|
|
423
464
|
return acc;
|
|
424
465
|
}, {});
|
|
425
466
|
}
|
|
426
467
|
};
|
|
468
|
+
var AES256GCM = class {
|
|
469
|
+
normalizedKey;
|
|
470
|
+
constructor(key) {
|
|
471
|
+
this.normalizedKey = crypto.createHash("sha256").update(key).digest().slice(0, 32);
|
|
472
|
+
}
|
|
473
|
+
// Pad payload to a multiple of 8 bytes
|
|
474
|
+
pad(payload) {
|
|
475
|
+
const padLength = 8 - payload.length % 8;
|
|
476
|
+
return Buffer.concat([payload, Buffer.alloc(padLength, padLength)]);
|
|
477
|
+
}
|
|
478
|
+
getNormalizedKey() {
|
|
479
|
+
return this.getNormalizedKey;
|
|
480
|
+
}
|
|
481
|
+
// Wrapping function
|
|
482
|
+
encrypt(payload) {
|
|
483
|
+
const normalizedWrappingKey = this.normalizedKey;
|
|
484
|
+
const paddedPayload = this.pad(Buffer.from(payload));
|
|
485
|
+
const iv = crypto.randomBytes(12);
|
|
486
|
+
const cipher = crypto.createCipheriv(
|
|
487
|
+
"aes-256-gcm",
|
|
488
|
+
normalizedWrappingKey,
|
|
489
|
+
iv
|
|
490
|
+
);
|
|
491
|
+
const encryptedPayload = Buffer.concat([
|
|
492
|
+
cipher.update(paddedPayload),
|
|
493
|
+
cipher.final()
|
|
494
|
+
]);
|
|
495
|
+
const authTag = cipher.getAuthTag();
|
|
496
|
+
return encryptedPayload.toString("base64") + "." + iv.toString("base64") + "." + authTag.toString("base64");
|
|
497
|
+
}
|
|
498
|
+
decrypt(payload) {
|
|
499
|
+
const [encryptedKey64, iv64, authTag64] = payload.split(".");
|
|
500
|
+
const encryptedPayload = Buffer.from(encryptedKey64, "base64");
|
|
501
|
+
const iv = Buffer.from(iv64, "base64");
|
|
502
|
+
const authTag = Buffer.from(authTag64, "base64");
|
|
503
|
+
const decipher = crypto.createDecipheriv(
|
|
504
|
+
"aes-256-gcm",
|
|
505
|
+
this.normalizedKey,
|
|
506
|
+
iv
|
|
507
|
+
);
|
|
508
|
+
decipher.setAuthTag(authTag);
|
|
509
|
+
const paddedKey = Buffer.concat([
|
|
510
|
+
decipher.update(encryptedPayload),
|
|
511
|
+
decipher.final()
|
|
512
|
+
]);
|
|
513
|
+
const padLength = paddedKey[paddedKey.length - 1];
|
|
514
|
+
return paddedKey.slice(0, -padLength).toString();
|
|
515
|
+
}
|
|
516
|
+
};
|
|
427
517
|
var env_default = EnvEngine;
|
|
428
518
|
|
|
429
519
|
// src-public/pubsub.ts
|