@develit-io/backend-sdk 5.41.0 → 5.42.0
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.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.mjs +34 -3
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -438,6 +438,17 @@ interface UseFetchOptions extends RequestInit {
|
|
|
438
438
|
}
|
|
439
439
|
declare function useFetch<T = unknown>(url: string, { parseAs, ...options }?: UseFetchOptions): Promise<Result<T>>;
|
|
440
440
|
|
|
441
|
+
declare const signPayload: ({ payload, privateKey, }: {
|
|
442
|
+
payload: string;
|
|
443
|
+
privateKey: string;
|
|
444
|
+
}) => Promise<string>;
|
|
445
|
+
declare const verifyPayloadSignature: ({ signature, data, publicKey, algorithm, }: {
|
|
446
|
+
signature: string;
|
|
447
|
+
data: string;
|
|
448
|
+
publicKey: string;
|
|
449
|
+
algorithm?: "RSA" | "EC" | "HMAC";
|
|
450
|
+
}) => Promise<boolean>;
|
|
451
|
+
|
|
441
452
|
declare const calculateExponentialBackoff: (attempts: number, baseDelaySeconds: number) => number;
|
|
442
453
|
|
|
443
454
|
declare const RPCResponse: {
|
|
@@ -527,5 +538,5 @@ interface WithRetryCounterOptions {
|
|
|
527
538
|
type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
|
|
528
539
|
declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
|
|
529
540
|
|
|
530
|
-
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, bankAccount, bankAccountMetadataSchema, base, bicSchema, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, idempotency, ip, isInternalError, jwt, logger, paginationQuerySchema, paginationSchema, service, signature, useFetch, useResult, useResultSync, uuidv4 };
|
|
541
|
+
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, bankAccount, bankAccountMetadataSchema, base, bicSchema, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, idempotency, ip, isInternalError, jwt, logger, paginationQuerySchema, paginationSchema, service, signPayload, signature, useFetch, useResult, useResultSync, uuidv4, verifyPayloadSignature };
|
|
531
542
|
export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, AuthUser, BankAccountMetadata, BaseEvent, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IdempotencyVariables, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, UserRole, UserVariables, ValidatedInput };
|
package/dist/index.d.ts
CHANGED
|
@@ -438,6 +438,17 @@ interface UseFetchOptions extends RequestInit {
|
|
|
438
438
|
}
|
|
439
439
|
declare function useFetch<T = unknown>(url: string, { parseAs, ...options }?: UseFetchOptions): Promise<Result<T>>;
|
|
440
440
|
|
|
441
|
+
declare const signPayload: ({ payload, privateKey, }: {
|
|
442
|
+
payload: string;
|
|
443
|
+
privateKey: string;
|
|
444
|
+
}) => Promise<string>;
|
|
445
|
+
declare const verifyPayloadSignature: ({ signature, data, publicKey, algorithm, }: {
|
|
446
|
+
signature: string;
|
|
447
|
+
data: string;
|
|
448
|
+
publicKey: string;
|
|
449
|
+
algorithm?: "RSA" | "EC" | "HMAC";
|
|
450
|
+
}) => Promise<boolean>;
|
|
451
|
+
|
|
441
452
|
declare const calculateExponentialBackoff: (attempts: number, baseDelaySeconds: number) => number;
|
|
442
453
|
|
|
443
454
|
declare const RPCResponse: {
|
|
@@ -527,5 +538,5 @@ interface WithRetryCounterOptions {
|
|
|
527
538
|
type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
|
|
528
539
|
declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
|
|
529
540
|
|
|
530
|
-
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, bankAccount, bankAccountMetadataSchema, base, bicSchema, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, idempotency, ip, isInternalError, jwt, logger, paginationQuerySchema, paginationSchema, service, signature, useFetch, useResult, useResultSync, uuidv4 };
|
|
541
|
+
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, bankAccount, bankAccountMetadataSchema, base, bicSchema, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, idempotency, ip, isInternalError, jwt, logger, paginationQuerySchema, paginationSchema, service, signPayload, signature, useFetch, useResult, useResultSync, uuidv4, verifyPayloadSignature };
|
|
531
542
|
export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, AuthUser, BankAccountMetadata, BaseEvent, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IdempotencyVariables, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, UserRole, UserVariables, ValidatedInput };
|
package/dist/index.mjs
CHANGED
|
@@ -473,6 +473,37 @@ const logResponse = (log) => {
|
|
|
473
473
|
console.log(`RESPONSE | An outgoing response has been recorded.`, log);
|
|
474
474
|
};
|
|
475
475
|
|
|
476
|
+
const signPayload = async ({
|
|
477
|
+
payload,
|
|
478
|
+
privateKey
|
|
479
|
+
}) => {
|
|
480
|
+
const binaryPrivateKey = Uint8Array.from(
|
|
481
|
+
atob(privateKey),
|
|
482
|
+
(c) => c.charCodeAt(0)
|
|
483
|
+
);
|
|
484
|
+
const importedPrivateKey = await crypto.subtle.importKey(
|
|
485
|
+
"pkcs8",
|
|
486
|
+
binaryPrivateKey,
|
|
487
|
+
{
|
|
488
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
489
|
+
hash: "SHA-256"
|
|
490
|
+
},
|
|
491
|
+
false,
|
|
492
|
+
["sign"]
|
|
493
|
+
);
|
|
494
|
+
const encodedPayload = new TextEncoder().encode(payload);
|
|
495
|
+
const signature = await crypto.subtle.sign(
|
|
496
|
+
{
|
|
497
|
+
name: "RSASSA-PKCS1-v1_5"
|
|
498
|
+
},
|
|
499
|
+
importedPrivateKey,
|
|
500
|
+
encodedPayload
|
|
501
|
+
);
|
|
502
|
+
const base64Signature = btoa(
|
|
503
|
+
String.fromCharCode(...new Uint8Array(signature))
|
|
504
|
+
);
|
|
505
|
+
return base64Signature;
|
|
506
|
+
};
|
|
476
507
|
const algParams = {
|
|
477
508
|
RSA: {
|
|
478
509
|
name: "RSASSA-PKCS1-v1_5",
|
|
@@ -487,7 +518,7 @@ const algParams = {
|
|
|
487
518
|
hash: { name: "SHA-256" }
|
|
488
519
|
}
|
|
489
520
|
};
|
|
490
|
-
const
|
|
521
|
+
const verifyPayloadSignature = async ({
|
|
491
522
|
signature,
|
|
492
523
|
data,
|
|
493
524
|
publicKey,
|
|
@@ -691,7 +722,7 @@ const signature = () => {
|
|
|
691
722
|
message: "Signature key not found."
|
|
692
723
|
});
|
|
693
724
|
}
|
|
694
|
-
const isVerified = await
|
|
725
|
+
const isVerified = await verifyPayloadSignature({
|
|
695
726
|
signature: signatureHeader,
|
|
696
727
|
publicKey: signatureKey.publicKey,
|
|
697
728
|
data: payload
|
|
@@ -948,4 +979,4 @@ function develitWorker(Worker) {
|
|
|
948
979
|
return DevelitWorker;
|
|
949
980
|
}
|
|
950
981
|
|
|
951
|
-
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, bankAccount, bankAccountMetadataSchema, base, bicSchema, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, idempotency, ip, isInternalError, jwt, logger, paginationQuerySchema, paginationSchema, service, signature, useFetch, useResult, useResultSync, uuidv4 };
|
|
982
|
+
export { DatabaseTransaction, ENVIRONMENT, RPCResponse, USER_ROLES, action, bankAccount, bankAccountMetadataSchema, base, bicSchema, calculateExponentialBackoff, cloudflareQueue, composeWranglerBase, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getSecret, handleAction, handleActionResponse, ibanSchema, idempotency, ip, isInternalError, jwt, logger, paginationQuerySchema, paginationSchema, service, signPayload, signature, useFetch, useResult, useResultSync, uuidv4, verifyPayloadSignature };
|