franchising 0.7.0 → 0.8.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/README.md +13 -72
- package/dist/{accounts-TyMPSHM0.cjs → accounts-BscmRiXc.cjs} +26 -1
- package/dist/{accounts-TyMPSHM0.cjs.map → accounts-BscmRiXc.cjs.map} +1 -1
- package/dist/{accounts-B4bnTXUd.js → accounts-DJRg4gXj.js} +26 -1
- package/dist/{accounts-B4bnTXUd.js.map → accounts-DJRg4gXj.js.map} +1 -1
- package/dist/cli.js +2 -2
- package/dist/{index-CNlb6WNr.d.ts → index-Bl4Ka1Wr.d.ts} +2 -2
- package/dist/{index-I_Nx5SsQ.d.cts → index-CBue43h0.d.cts} +2 -2
- package/dist/{index-B_byXBRW.d.ts → index-cKCKFKLi.d.cts} +181 -5
- package/dist/{index-B_byXBRW.d.cts → index-cKCKFKLi.d.ts} +181 -5
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/messaging/index.cjs +1 -1
- package/dist/messaging/index.d.cts +1 -1
- package/dist/messaging/index.d.ts +1 -1
- package/dist/messaging/index.js +1 -1
- package/dist/sso/client.d.cts +2 -2
- package/dist/sso/client.d.ts +2 -2
- package/dist/sso/index.cjs +72 -1
- package/dist/sso/index.cjs.map +1 -1
- package/dist/sso/index.d.cts +2 -2
- package/dist/sso/index.d.ts +2 -2
- package/dist/sso/index.js +72 -1
- package/dist/sso/index.js.map +1 -1
- package/dist/sso/nestjs.cjs +2 -2
- package/dist/sso/nestjs.d.cts +2 -2
- package/dist/sso/nestjs.d.ts +2 -2
- package/dist/sso/nestjs.js +2 -2
- package/dist/sso/resource.cjs +2 -2
- package/dist/sso/resource.d.cts +3 -3
- package/dist/sso/resource.d.ts +3 -3
- package/dist/sso/resource.js +2 -2
- package/dist/{verifier-BIBtPCVi.cjs → verifier-BYrFb8tg.cjs} +2 -2
- package/dist/{verifier-BIBtPCVi.cjs.map → verifier-BYrFb8tg.cjs.map} +1 -1
- package/dist/{verifier-DNdy5Ynw.js → verifier-DSvtdWuY.js} +2 -2
- package/dist/{verifier-DNdy5Ynw.js.map → verifier-DSvtdWuY.js.map} +1 -1
- package/dist/version-8Zc_uUvG.js +1 -0
- package/dist/{version-iERj9NJ6.cjs → version-BMXokpna.cjs} +1 -1
- package/package.json +1 -1
- package/dist/version-Cm1EJ-YK.js +0 -1
|
@@ -252,10 +252,11 @@ type SchoolRef = string | {
|
|
|
252
252
|
/**
|
|
253
253
|
* De onde veio o papel: `joy` (sincronização), `invite` (convite da
|
|
254
254
|
* gestão de equipe), `franchisor` (franqueadora), `app` (concedido por um
|
|
255
|
-
* aplicativo)
|
|
256
|
-
*
|
|
255
|
+
* aplicativo com o token dele), `app_admin` (concedido por um admin do app,
|
|
256
|
+
* pelo dashboard) ou `sandbox` (persona de teste, só em apps de
|
|
257
|
+
* desenvolvimento e homologação).
|
|
257
258
|
*/
|
|
258
|
-
type TeamRoleOrigin = 'joy' | 'invite' | 'franchisor' | 'app' | 'sandbox';
|
|
259
|
+
type TeamRoleOrigin = 'joy' | 'invite' | 'franchisor' | 'app' | 'app_admin' | 'sandbox';
|
|
259
260
|
interface TeamRole {
|
|
260
261
|
key: string;
|
|
261
262
|
origin: TeamRoleOrigin;
|
|
@@ -294,6 +295,53 @@ interface TeamInvitation {
|
|
|
294
295
|
accountCreated: boolean;
|
|
295
296
|
granted: string[];
|
|
296
297
|
}
|
|
298
|
+
/** Um papel do app que o admin dele concede. */
|
|
299
|
+
interface AppRole {
|
|
300
|
+
key: string;
|
|
301
|
+
name: string;
|
|
302
|
+
description: string;
|
|
303
|
+
organizationTypes: ('franqueadora' | 'escola')[];
|
|
304
|
+
}
|
|
305
|
+
interface AppRoleList {
|
|
306
|
+
/** Chave do app (o do cliente que emitiu o token). */
|
|
307
|
+
application: string;
|
|
308
|
+
/** Os papéis que cabem na organização, sem o de admin do app. */
|
|
309
|
+
items: AppRole[];
|
|
310
|
+
}
|
|
311
|
+
/** Um papel do app de uma pessoa, uma vez por origem. */
|
|
312
|
+
interface AppRoleGrant {
|
|
313
|
+
key: string;
|
|
314
|
+
origin: TeamRoleOrigin;
|
|
315
|
+
grantedAt: string;
|
|
316
|
+
/** Quem concedeu, quando foi uma pessoa; `null` para o backend do app. */
|
|
317
|
+
grantedBy: {
|
|
318
|
+
userId: string;
|
|
319
|
+
name: string | null;
|
|
320
|
+
} | null;
|
|
321
|
+
}
|
|
322
|
+
interface AppRoleMember {
|
|
323
|
+
userId: string;
|
|
324
|
+
name: string;
|
|
325
|
+
email: string;
|
|
326
|
+
status: 'active' | 'pending' | 'disabled';
|
|
327
|
+
/** Só os papéis do app na organização. */
|
|
328
|
+
roles: AppRoleGrant[];
|
|
329
|
+
}
|
|
330
|
+
interface AppRoleMembersQuery {
|
|
331
|
+
/** Busca por nome ou e-mail. */
|
|
332
|
+
q?: string | undefined;
|
|
333
|
+
/** Só quem tem este papel do app. */
|
|
334
|
+
role?: string | undefined;
|
|
335
|
+
cursor?: string | undefined;
|
|
336
|
+
limit?: number | undefined;
|
|
337
|
+
}
|
|
338
|
+
interface AppRoleInvitationInput {
|
|
339
|
+
email: string;
|
|
340
|
+
/** Só é usado quando a conta é criada agora. */
|
|
341
|
+
name: string;
|
|
342
|
+
/** De 1 a 10 papéis do app (nunca o de admin). */
|
|
343
|
+
roles: string[];
|
|
344
|
+
}
|
|
297
345
|
interface RockfellerOptions {
|
|
298
346
|
/** Client ID do app, cadastrado em Admin → Aplicativos. */
|
|
299
347
|
clientId: string;
|
|
@@ -720,6 +768,7 @@ declare function rockfeller(options: RockfellerOptions): {
|
|
|
720
768
|
invite: "invite";
|
|
721
769
|
franchisor: "franchisor";
|
|
722
770
|
app: "app";
|
|
771
|
+
app_admin: "app_admin";
|
|
723
772
|
sandbox: "sandbox";
|
|
724
773
|
}>>;
|
|
725
774
|
cursor: import("zod").ZodOptional<import("zod").ZodString>;
|
|
@@ -798,6 +847,133 @@ declare function rockfeller(options: RockfellerOptions): {
|
|
|
798
847
|
}, {
|
|
799
848
|
revoked: string[];
|
|
800
849
|
}>;
|
|
850
|
+
listAppRoles: import("better-call").StrictEndpoint<"/rockfeller/app-roles", {
|
|
851
|
+
method: "GET";
|
|
852
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
853
|
+
session: {
|
|
854
|
+
session: Record<string, any> & {
|
|
855
|
+
id: string;
|
|
856
|
+
createdAt: Date;
|
|
857
|
+
updatedAt: Date;
|
|
858
|
+
userId: string;
|
|
859
|
+
expiresAt: Date;
|
|
860
|
+
token: string;
|
|
861
|
+
ipAddress?: string | null | undefined;
|
|
862
|
+
userAgent?: string | null | undefined;
|
|
863
|
+
};
|
|
864
|
+
user: Record<string, any> & {
|
|
865
|
+
id: string;
|
|
866
|
+
createdAt: Date;
|
|
867
|
+
updatedAt: Date;
|
|
868
|
+
email: string;
|
|
869
|
+
emailVerified: boolean;
|
|
870
|
+
name: string;
|
|
871
|
+
image?: string | null | undefined;
|
|
872
|
+
};
|
|
873
|
+
};
|
|
874
|
+
}>>[];
|
|
875
|
+
query: import("zod").ZodObject<{
|
|
876
|
+
organization: import("zod").ZodString;
|
|
877
|
+
}, import("zod/v4/core").$strip>;
|
|
878
|
+
}, AppRoleList>;
|
|
879
|
+
listAppRoleMembers: import("better-call").StrictEndpoint<"/rockfeller/app-roles/members", {
|
|
880
|
+
method: "GET";
|
|
881
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
882
|
+
session: {
|
|
883
|
+
session: Record<string, any> & {
|
|
884
|
+
id: string;
|
|
885
|
+
createdAt: Date;
|
|
886
|
+
updatedAt: Date;
|
|
887
|
+
userId: string;
|
|
888
|
+
expiresAt: Date;
|
|
889
|
+
token: string;
|
|
890
|
+
ipAddress?: string | null | undefined;
|
|
891
|
+
userAgent?: string | null | undefined;
|
|
892
|
+
};
|
|
893
|
+
user: Record<string, any> & {
|
|
894
|
+
id: string;
|
|
895
|
+
createdAt: Date;
|
|
896
|
+
updatedAt: Date;
|
|
897
|
+
email: string;
|
|
898
|
+
emailVerified: boolean;
|
|
899
|
+
name: string;
|
|
900
|
+
image?: string | null | undefined;
|
|
901
|
+
};
|
|
902
|
+
};
|
|
903
|
+
}>>[];
|
|
904
|
+
query: import("zod").ZodObject<{
|
|
905
|
+
organization: import("zod").ZodString;
|
|
906
|
+
q: import("zod").ZodOptional<import("zod").ZodString>;
|
|
907
|
+
role: import("zod").ZodOptional<import("zod").ZodString>;
|
|
908
|
+
cursor: import("zod").ZodOptional<import("zod").ZodString>;
|
|
909
|
+
limit: import("zod").ZodOptional<import("zod").ZodCoercedNumber<unknown>>;
|
|
910
|
+
}, import("zod/v4/core").$strip>;
|
|
911
|
+
}, Page<AppRoleMember>>;
|
|
912
|
+
inviteAppRoleMember: import("better-call").StrictEndpoint<"/rockfeller/app-roles/invite", {
|
|
913
|
+
method: "POST";
|
|
914
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
915
|
+
session: {
|
|
916
|
+
session: Record<string, any> & {
|
|
917
|
+
id: string;
|
|
918
|
+
createdAt: Date;
|
|
919
|
+
updatedAt: Date;
|
|
920
|
+
userId: string;
|
|
921
|
+
expiresAt: Date;
|
|
922
|
+
token: string;
|
|
923
|
+
ipAddress?: string | null | undefined;
|
|
924
|
+
userAgent?: string | null | undefined;
|
|
925
|
+
};
|
|
926
|
+
user: Record<string, any> & {
|
|
927
|
+
id: string;
|
|
928
|
+
createdAt: Date;
|
|
929
|
+
updatedAt: Date;
|
|
930
|
+
email: string;
|
|
931
|
+
emailVerified: boolean;
|
|
932
|
+
name: string;
|
|
933
|
+
image?: string | null | undefined;
|
|
934
|
+
};
|
|
935
|
+
};
|
|
936
|
+
}>>[];
|
|
937
|
+
body: import("zod").ZodObject<{
|
|
938
|
+
organization: import("zod").ZodString;
|
|
939
|
+
email: import("zod").ZodString;
|
|
940
|
+
name: import("zod").ZodString;
|
|
941
|
+
roles: import("zod").ZodArray<import("zod").ZodString>;
|
|
942
|
+
}, import("zod/v4/core").$strip>;
|
|
943
|
+
}, TeamInvitation>;
|
|
944
|
+
revokeAppRoles: import("better-call").StrictEndpoint<"/rockfeller/app-roles/revoke", {
|
|
945
|
+
method: "POST";
|
|
946
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
947
|
+
session: {
|
|
948
|
+
session: Record<string, any> & {
|
|
949
|
+
id: string;
|
|
950
|
+
createdAt: Date;
|
|
951
|
+
updatedAt: Date;
|
|
952
|
+
userId: string;
|
|
953
|
+
expiresAt: Date;
|
|
954
|
+
token: string;
|
|
955
|
+
ipAddress?: string | null | undefined;
|
|
956
|
+
userAgent?: string | null | undefined;
|
|
957
|
+
};
|
|
958
|
+
user: Record<string, any> & {
|
|
959
|
+
id: string;
|
|
960
|
+
createdAt: Date;
|
|
961
|
+
updatedAt: Date;
|
|
962
|
+
email: string;
|
|
963
|
+
emailVerified: boolean;
|
|
964
|
+
name: string;
|
|
965
|
+
image?: string | null | undefined;
|
|
966
|
+
};
|
|
967
|
+
};
|
|
968
|
+
}>>[];
|
|
969
|
+
body: import("zod").ZodObject<{
|
|
970
|
+
organization: import("zod").ZodString;
|
|
971
|
+
userId: import("zod").ZodString;
|
|
972
|
+
roles: import("zod").ZodArray<import("zod").ZodString>;
|
|
973
|
+
}, import("zod/v4/core").$strip>;
|
|
974
|
+
}, {
|
|
975
|
+
revoked: string[];
|
|
976
|
+
}>;
|
|
801
977
|
rockfellerBackchannelLogout: import("better-call").StrictEndpoint<"/rockfeller/backchannel-logout", {
|
|
802
978
|
method: "POST";
|
|
803
979
|
body: import("zod").ZodObject<{
|
|
@@ -837,5 +1013,5 @@ declare function rockfeller(options: RockfellerOptions): {
|
|
|
837
1013
|
max: number;
|
|
838
1014
|
}[];
|
|
839
1015
|
};
|
|
840
|
-
export {
|
|
841
|
-
//# sourceMappingURL=index-
|
|
1016
|
+
export { Preferences as A, PROVIDER_ID as B, SchoolList as C, SchoolType as D, SchoolRef as E, RockfellerError as F, WebhookMembershipData as G, WebhookEvent as H, isRockfellerError as I, WEBHOOK_EVENT_TYPES as J, WebhookUser as K, RockfellerErrorCode as L, ReducedMotion as M, Theme as N, Contrast as O, Timezone as P, ProfileTab as R, School as S, SchoolPermissions as T, WebhookEventData as U, TEAM_PROVIDER_ID as V, WebhookEventType as W, verifyWebhook as X, WebhookVerificationError as Y, TeamMembersQuery as _, RockfellerWebhookInput as a, TeamRoleOrigin as b, AppRoleGrant as c, AppRoleMember as d, AppRoleMembersQuery as f, TeamMember as g, TeamInvitationInput as h, RockfellerWebhookHooks as i, PreferencesPatch as j, HourCycle as k, AppRoleInvitationInput as l, TeamInvitation as m, RockfellerOptions as n, RockfellerWebhookOptions as o, Page as p, WebhookUserField as q, RockfellerSessionEndedInput as r, AppRole as s, rockfeller as t, AppRoleList as u, TeamRole as v, SchoolMembership as w, Permission as x, TeamRoleKey as y, DEFAULT_ISSUER as z };
|
|
1017
|
+
//# sourceMappingURL=index-cKCKFKLi.d.ts.map
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./version-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./version-BMXokpna.cjs");exports.version=e.t;
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{t as version}from"./version-
|
|
1
|
+
export{t as version}from"./version-8Zc_uUvG.js";
|
package/dist/messaging/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../version-iERj9NJ6.cjs"),t=1048576,n=20*t,r=5*t,i=10*t,a=1024,o=2048,s=[`upload`,`url`],c=[`attachment`,`inline`],l=[`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/vnd.ms-powerpoint`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`],u=[`application/pdf`,`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`text/csv`,`text/plain`,...l,`application/vnd.oasis.opendocument.text`,`application/vnd.oasis.opendocument.spreadsheet`,`application/zip`,`text/calendar`],d=/* @__PURE__ */ `apk.app.bat.cmd.com.cpl.dll.dmg.exe.hta.jar.js.jse.lnk.msi.msp.pif.ps1.reg.scr.sh.vb.vbe.vbs.wsf.wsh`.split(`.`),f=[`image`,`video`,`audio`,`document`],p={image:[`image/jpeg`,`image/png`],video:[`video/mp4`,`video/3gpp`],audio:[`audio/aac`,`audio/mp4`,`audio/mpeg`,`audio/amr`,`audio/ogg`],document:[`application/pdf`,...l,`text/plain`,`text/csv`,`application/zip`]},m={image:r,video:i,audio:i,document:i},ee=/* @__PURE__ */ `UNAUTHENTICATED.INVALID_API_KEY.ACTIVE_PROJECT_REQUIRED.PROJECT_ROLE_REQUIRED.VALIDATION_ERROR.FROM_DOMAIN_NOT_VERIFIED.SENDER_NOT_FOUND.WHATSAPP_TEMPLATE_NOT_FOUND.WHATSAPP_TEMPLATE_CONFLICT.WHATSAPP_TEMPLATE_PROVIDER_UNSUPPORTED.WHATSAPP_TEMPLATE_SUBMISSION_FAILED.WHATSAPP_TEMPLATE_SYNC_FAILED.WHATSAPP_TEMPLATE_INVALID_STATE.WHATSAPP_TEMPLATE_BODY_CONFLICT.ATTACHMENTS_NOT_SUPPORTED_FOR_CHANNEL.ATTACHMENTS_PROVIDER_TEMPLATE_CONFLICT.ATTACHMENT_INVALID.ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED.ATTACHMENT_TOO_LARGE.ATTACHMENTS_LIMIT_EXCEEDED.ATTACHMENT_URL_NOT_ALLOWED.WHATSAPP_CAPTION_INVALID.PAYLOAD_TOO_LARGE.ATTACHMENT_STORAGE_UNAVAILABLE.ATTACHMENT_STORAGE_NOT_CONFIGURED.ATTACHMENT_EXPIRED.MESSAGE_NOT_FOUND.SUPPRESSION_NOT_FOUND.MESSAGE_NOT_RETRYABLE.MESSAGE_CONTENT_EXPIRED.IDEMPOTENCY_KEY_REUSED.ROUTE_NOT_FOUND.INTERNAL_SERVER_ERROR.RATE_LIMIT_EXCEEDED.CONNECTION_ERROR.TIMEOUT.UNEXPECTED_RESPONSE`.split(`.`);var h=class extends Error{name=`MessagingError`;code;status;errors;constructor(e){super(e.message,{cause:e.cause}),this.code=e.code,this.status=e.status,this.errors=e.errors}get retryable(){return this.status===0||this.status===408||this.status===429||this.status>=500}toJSON(){return{name:this.name,code:this.code,message:this.message,status:this.status,...this.errors?{errors:this.errors}:{}}}},g=class extends h{name=`ValidationError`},_=class extends h{name=`AuthenticationError`},v=class extends h{name=`PermissionError`},y=class extends h{name=`NotFoundError`},b=class extends h{name=`RateLimitError`;retryAfter;constructor(e){super(e),this.retryAfter=e.retryAfter}},x=class extends h{name=`ServerError`},S=class extends h{name=`ConnectionError`},C=class extends h{name=`TimeoutError`};function w(e){return e instanceof h}function T(e){let t={code:e.code,message:e.message,status:e.status,...e.errors?{errors:e.errors}:{}};return e.status===429?new b({...t,...e.retryAfter===void 0?{}:{retryAfter:e.retryAfter}}):e.status>=500?new x(t):e.status===401?new _(t):e.status===403?new v(t):e.status===404?new y(t):e.status===400||e.status===422?new g(t):new h(t)}function te(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!==void 0){if(Array.isArray(r))for(let e of r)t.append(n,String(e));else t.append(n,r instanceof Date?r.toISOString():String(r))}let n=t.toString();return n?`?${n}`:``}const E=8e3,ne=e=>new Promise(t=>setTimeout(t,e));function re(e,t){if(t!==void 0)return Math.min(t*1e3,E);let n=Math.min(500*2**e,E);return Math.round(n*(.5+Math.random()*.5))}function ie(e){if(!e)return;let t=Number(e);if(Number.isFinite(t)&&t>=0)return t;let n=Date.parse(e);if(!Number.isNaN(n))return Math.max(0,Math.round((n-Date.now())/1e3))}function D(e){if(e.length===1)return e[0];let t=AbortSignal.any;if(t)return t(e);let n=new AbortController;for(let t of e){if(t.aborted){n.abort(t.reason);break}t.addEventListener(`abort`,()=>n.abort(t.reason),{once:!0})}return n.signal}function O(e){return{data:e,error:null}}function k(e){return{data:null,error:e}}const A=e.t,ae=`rockdev-messaging-node/${A}`;var oe=class{config;constructor(e){this.config=e}async request(e){let t=`${this.config.baseUrl}/v1${e.path}${e.query?te(e.query):``}`,n=e.method===`GET`||e.idempotencyKey!==void 0?this.config.maxRetries:0,r;for(let i=0;i<=n;i+=1){let a=await this.attempt(t,e);if(a.error===null)return a;if(r=a.error,!a.error.retryable||e.options?.signal?.aborted||i===n)break;await ne(re(i,a.error.retryAfter))}return k(r)}async attempt(e,t){let n=t.options?.timeout??this.config.timeout,r=new AbortController,i=setTimeout(()=>r.abort(),n),a=[r.signal];t.options?.signal&&a.push(t.options.signal);let o;try{o=await this.config.fetch(e,{method:t.method,headers:this.headers(t),signal:D(a),...t.body===void 0?{}:{body:JSON.stringify(t.body)}})}catch(e){return t.options?.signal?.aborted?k(new h({code:`CONNECTION_ERROR`,message:`The request was aborted by the caller.`,status:0,cause:e})):r.signal.aborted?k(new C({code:`TIMEOUT`,message:`The request did not complete within ${n}ms.`,status:0,cause:e})):k(new S({code:`CONNECTION_ERROR`,message:e instanceof Error?e.message:`The request could not reach the Messaging API.`,status:0,cause:e}))}finally{clearTimeout(i)}return this.parse(o)}headers(e){let t=e=>Object.fromEntries(Object.entries(e).filter(([e])=>e.toLowerCase()!==`idempotency-key`));return{accept:`application/json`,authorization:`Bearer ${this.config.secret}`,"user-agent":ae,...e.body===void 0?{}:{"content-type":`application/json`},...t(this.config.headers),...t(e.options?.headers??{}),...e.idempotencyKey===void 0?{}:{"idempotency-key":e.idempotencyKey}}}async parse(e){let t=await e.text().catch(()=>``),n;try{n=t?JSON.parse(t):void 0}catch{n=void 0}if(!e.ok){let t=ie(e.headers.get(`retry-after`));return k(T({code:n?.code??`INTERNAL_SERVER_ERROR`,message:n?.message??`The Messaging API responded with ${e.status}.`,status:e.status,...n?.errors?{errors:n.errors}:{},...t===void 0?{}:{retryAfter:t}}))}return!n||n.data===void 0?k(new h({code:`UNEXPECTED_RESPONSE`,message:`The Messaging API responded without the expected body.`,status:e.status})):O(n.data)}},j=class{messages;constructor(e){this.messages=e}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:typeof n==`string`?{email:n}:n},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:typeof e==`string`?{email:e}:e})),t)}},M=class e{fetchPage;messages;nextCursor;constructor(e,t){this.fetchPage=t,this.messages=e.messages,this.nextCursor=e.nextCursor}get hasMore(){return this.nextCursor!==null}async next(){return this.nextCursor===null?{data:new e({messages:[],nextCursor:null},this.fetchPage),error:null}:this.fetchPage(this.nextCursor)}async*[Symbol.asyncIterator](){let e=this;for(;;){for(let t of e.messages)yield t;if(!e.hasMore)return;let{data:t,error:n}=await e.next();if(n)throw n;e=t}}};function N(e){if(e!==void 0)return e instanceof Date?e.toISOString():e}function se(e){return{status:e.status,channel:e.channel,to:e.to,search:e.search,scheduled:e.scheduled,createdAfter:N(e.createdAfter),createdBefore:N(e.createdBefore),limit:e.limit,cursor:e.cursor}}const P=24576;function ce(e){if(typeof e.toBase64==`function`)return e.toBase64();let t=globalThis.Buffer;if(t)return t.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`);let n=``;for(let t=0;t<e.length;t+=P){let r=e.subarray(t,t+P),i=``;for(let e=0;e<r.length;e+=1)i+=String.fromCharCode(r[e]);n+=btoa(i)}return n}function le(e){let t=e.endsWith(`==`)?2:+!!e.endsWith(`=`);return e.length/4*3-t}function ue(e){return typeof Blob<`u`&&e instanceof Blob}function de(e){return`email`in e&&e.email!==void 0?`email`:`whatsapp`in e&&e.whatsapp!==void 0?`whatsapp`:`sms`in e&&e.sms!==void 0?`sms`:`webpush`}function fe(e){return typeof e==`string`?e.includes(`@`)?{email:e}:{whatsapp:e}:e}function F(e){let t=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(e);if(!t)return null;let[n,r]=[Number(t[1]),Number(t[2])];return n===0||n===10||n===127||n===100&&r>=64&&r<=127||n===169&&r===254||n===172&&r>=16&&r<=31||n===192&&r===168||n===198&&(r===18||r===19)||n>=224}function I(e){if(!e.startsWith(`[`))return null;let t=e.slice(1,-1).toLowerCase(),n=/^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(t);return n?.[1]?F(n[1])??!0:t===`::`||t===`::1`||t.startsWith(`::ffff:`)||/^f[cd]/.test(t)||/^fe[89ab]/.test(t)||t.startsWith(`ff`)}function L(e){try{return new URL(e)}catch{return null}}const R={pdf:`application/pdf`,png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,gif:`image/gif`,webp:`image/webp`,csv:`text/csv`,txt:`text/plain`,doc:`application/msword`,docx:`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,xls:`application/vnd.ms-excel`,xlsx:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,ppt:`application/vnd.ms-powerpoint`,pptx:`application/vnd.openxmlformats-officedocument.presentationml.presentation`,odt:`application/vnd.oasis.opendocument.text`,ods:`application/vnd.oasis.opendocument.spreadsheet`,zip:`application/zip`,ics:`text/calendar`,mp4:`video/mp4`,"3gp":`video/3gpp`,aac:`audio/aac`,m4a:`audio/mp4`,mp3:`audio/mpeg`,amr:`audio/amr`,ogg:`audio/ogg`,opus:`audio/ogg`};function z(e){return(e.split(`;`)[0]??``).trim().toLowerCase()}function B(e){let t=e.lastIndexOf(`.`);return t<=0||t===e.length-1?``:e.slice(t+1).toLowerCase()}function V(e){let t=z(e);for(let e of f)if(p[e].includes(t))return e;return null}function pe(e){return R[B(e.trim())]}const me=/^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*(\s*;.*)?$/i,he=/^[A-Za-z0-9+/]*={0,2}$/,ge=/[/\\\u0000-\u001f\u007f]/;var H=class{code;message;detail;constructor(e,t,n){this.code=e,this.message=t,this.detail=n}};function U(e,t,n=t){throw new H(e,t,n)}function _e(e,t){let n=e=>U(`ATTACHMENT_URL_NOT_ALLOWED`,`The attachment URL is not allowed: ${e}.`,`${t}.url ${e}`);e.length>2048&&n(`must be at most ${o} characters long`);let r=L(e)??n(`must be a valid URL`);r.protocol!==`https:`&&n(`must use https`),(r.username||r.password)&&n(`must not contain credentials`),r.port&&r.port!==`443`&&n(`must use the default port`);let i=r.hostname.toLowerCase().replace(/\.$/,``);(i===`localhost`||i.endsWith(`.localhost`)||i.endsWith(`.local`)||i.endsWith(`.internal`))&&n(`must not point to a local host`),!i.startsWith(`[`)&&!i.includes(`.`)&&n(`must use a fully qualified host name`),(F(i)||I(i))&&n(`must not point to a private address`)}async function ve(e,t){let n=e=>U(`ATTACHMENT_INVALID`,`The attachment is invalid.`,e);typeof e==`object`&&e||n(`${t} must be an object`);let{filename:r,disposition:i,contentId:a}=e;(typeof r!=`string`||r.trim()===``)&&n(`${t}.filename is required`),r.length>255&&n(`${t}.filename must be at most 255 characters long`),ge.test(r)&&n(`${t}.filename must not contain path separators or control characters`);let o=`url`in e&&e.url!==void 0;o===(`content`in e&&e.content!==void 0)&&n(`${t} must have exactly one of url or content`),i!==void 0&&!c.includes(i)&&n(`${t}.disposition must be one of attachment, inline`),a!==void 0&&(typeof a!=`string`||a===``||a.length>255)&&n(`${t}.contentId must be a non-empty string of at most 255 characters`),i===`inline`&&(a??``).trim()===``&&n(`${t}.contentId is required for inline attachments`);let s={...i===void 0?{}:{disposition:i},...a===void 0?{}:{contentId:a}},l=e=>e===void 0||e.trim()===``?n(`${t}.contentType is required`):(me.test(e)||n(`${t}.contentType must be a type/subtype MIME type`),e);if(o){let{url:i}=e;return typeof i==`string`?(_e(i,t),{body:{filename:r,contentType:l(e.contentType),url:i,...s},size:null}):n(`${t}.url must be a string`)}let{content:u}=e,d,f,p;if(typeof u==`string`)u.length%4==0&&he.test(u)||n(`${t}.content must be valid base64`),d=u,f=le(u);else{let e;if(u instanceof Uint8Array)e=u;else if(u instanceof ArrayBuffer)e=new Uint8Array(u);else if(ArrayBuffer.isView(u))e=new Uint8Array(u.buffer,u.byteOffset,u.byteLength);else if(ue(u))p=u.type||void 0,e=new Uint8Array(await u.arrayBuffer());else return n(`${t}.content must be a Uint8Array, ArrayBuffer, Blob or base64 string`);d=ce(e),f=e.byteLength}return{body:{filename:r,contentType:l(e.contentType??p??pe(r)),content:d,...s},size:f}}function ye(e,t,r){if(e===`email`){t.length>10&&U(`ATTACHMENTS_LIMIT_EXCEEDED`,`An email accepts at most 10 attachments.`);let e=0;t.forEach(({body:t,size:n},r)=>{let i=`attachments.${r}`;u.includes(z(t.contentType))||U(`ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED`,`The attachment content type is not allowed for email.`,`${i}.contentType ${z(t.contentType)} is not allowed`),d.includes(B(t.filename.trim()))&&U(`ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED`,`The attachment file extension is not allowed.`,`${i}.filename has a blocked extension`),e+=n??0}),e>20971520&&U(`ATTACHMENT_TOO_LARGE`,`Email attachments must add up to at most ${n} bytes.`);return}t.length>1&&U(`ATTACHMENTS_LIMIT_EXCEEDED`,`A WhatsApp message accepts at most 1 attachment.`);let[i]=t;if(!i)return;let o=`attachments.0`;(i.body.disposition!==void 0||i.body.contentId!==void 0)&&U(`ATTACHMENT_INVALID`,`The attachment is invalid.`,`${o}.disposition and contentId are email-only`);let s=V(i.body.contentType);s||U(`ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED`,`The attachment content type is not allowed for WhatsApp.`,`${o}.contentType ${z(i.body.contentType)} is not allowed`);let c=m[s];i.size!==null&&i.size>c&&U(`ATTACHMENT_TOO_LARGE`,`WhatsApp ${s} attachments must be at most ${c} bytes.`),r!==void 0&&s===`audio`&&U(`WHATSAPP_CAPTION_INVALID`,`WhatsApp audio does not accept a caption.`,`content must be empty for audio attachments`),r!==void 0&&r.length>1024&&U(`WHATSAPP_CAPTION_INVALID`,`A WhatsApp caption must be at most ${a} characters long.`,`content must be at most ${a} characters long`)}async function be(e,t,n=``){try{let n=de(e.to);n!==`email`&&n!==`whatsapp`&&U(`ATTACHMENTS_NOT_SUPPORTED_FOR_CHANNEL`,`Attachments are not supported for the ${n} channel.`),e.providerTemplate!==void 0&&U(`ATTACHMENTS_PROVIDER_TEMPLATE_CONFLICT`,`Attachments cannot be combined with providerTemplate.`),Array.isArray(t)||U(`ATTACHMENT_INVALID`,`The attachment is invalid.`,`attachments must be an array`);let r=[];for(let[e,n]of t.entries())r.push(await ve(n,`attachments.${e}`));return ye(n,r,e.content),O(r.map(({body:e})=>e))}catch(e){if(!(e instanceof H))throw e;return k(new g({code:e.code,message:e.message,status:400,errors:[`${n}${e.detail}`]}))}}function xe(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}async function W(e,t=``){let{to:n,sendAt:r,attachments:i,...a}=e,{idempotencyKey:o,...s}=a,c=fe(n),l;if(i!==void 0&&i.length>0){let e=await be({to:c,content:s.content,providerTemplate:s.providerTemplate},i,t);if(e.error)return k(e.error);l=e.data}return O(xe({...s,to:c,sendAt:N(r),attachments:l}))}var G=class{http;constructor(e){this.http=e}async send(e,t){let n=await W(e);return n.error?k(n.error):this.http.request({method:`POST`,path:`/messages`,body:n.data,...e.idempotencyKey===void 0?{}:{idempotencyKey:e.idempotencyKey},...t?{options:t}:{}})}async batch(e,t){let{idempotencyKey:n,...r}=t??{},i=[];for(let[t,n]of e.entries()){let e=await W(n,`${t}.`);if(e.error)return k(e.error);i.push(e.data)}return this.http.request({method:`POST`,path:`/messages/batch`,body:i,...n===void 0?{}:{idempotencyKey:n},...t?{options:r}:{}})}async create(e,t){return this.send(e,t)}async retry(e,t,n){return this.http.request({method:`POST`,path:`/messages/${encodeURIComponent(e)}/retry`,idempotencyKey:t.idempotencyKey,...n?{options:n}:{}})}async get(e,t){return this.http.request({method:`GET`,path:`/messages/${encodeURIComponent(e)}`,...t?{options:t}:{}})}async retrieve(e,t){return this.get(e,t)}async list(e={},t){let{data:n,error:r}=await this.http.request({method:`GET`,path:`/messages`,query:se(e),...t?{options:t}:{}});return r?{data:null,error:r}:{data:new M(n,n=>this.list({...e,cursor:n},t)),error:null}}},K=class{messages;constructor(e){this.messages=e}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:typeof n==`string`?{sms:n}:n},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:typeof e==`string`?{sms:e}:e})),t)}},q=class{http;constructor(e){this.http=e}create(e,t){return this.http.request({method:`POST`,path:`/suppressions`,body:e,...t?{options:t}:{}})}batch(e,t){return this.http.request({method:`POST`,path:`/suppressions/batch`,body:e,...t?{options:t}:{}})}get(e,t){return this.http.request({method:`GET`,path:`/suppressions/${encodeURIComponent(e)}`,...t?{options:t}:{}})}list(e={},t){return this.http.request({method:`GET`,path:`/suppressions`,query:{email:e.email,reason:e.reason,limit:e.limit,cursor:e.cursor},...t?{options:t}:{}})}delete(e,t){return this.http.request({method:`DELETE`,path:`/suppressions/${encodeURIComponent(e)}`,...t?{options:t}:{}})}batchDelete(e,t){return this.http.request({method:`POST`,path:`/suppressions/batch/delete`,body:e,...t?{options:t}:{}})}},J=class{messages;http;constructor(e,t){this.messages=e,this.http=t}async createSubscriptionToken(e,t){return this.http.request({method:`POST`,path:`/webpush/subscription-tokens`,body:e,...t?{options:t}:{}})}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:{webpush:typeof n==`string`?{recipientId:n}:n}},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:{webpush:typeof e==`string`?{recipientId:e}:e}})),t)}},Y=class{messages;constructor(e){this.messages=e}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:typeof n==`string`?{whatsapp:n}:n},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:typeof e==`string`?{whatsapp:e}:e})),t)}},X=class{http;constructor(e){this.http=e}list(e={},t){return this.http.request({method:`GET`,path:`/whatsapp-templates`,query:{senderId:e.senderId},...t?{options:t}:{}})}get(e,t){return this.http.request({method:`GET`,path:`/whatsapp-templates/${encodeURIComponent(e)}`,...t?{options:t}:{}})}create(e,t){return this.http.request({method:`POST`,path:`/whatsapp-templates`,body:e,...t?{options:t}:{}})}update(e,t,n){return this.http.request({method:`PATCH`,path:`/whatsapp-templates/${encodeURIComponent(e)}`,body:t,...n?{options:n}:{}})}submit(e,t,n){return this.http.request({method:`POST`,path:`/whatsapp-templates/${encodeURIComponent(e)}/submit`,body:t,...n?{options:n}:{}})}sync(e,t){return this.http.request({method:`POST`,path:`/whatsapp-templates/sync`,body:e,...t?{options:t}:{}})}};function Se(e){return(globalThis.process?.env?.[e])?.trim()||void 0}var Z=class{messages;emails;whatsapp;whatsappTemplates;sms;webPush;suppressions;constructor(e){let t=typeof e==`string`?{secret:e}:e,n=t.secret?.trim();if(!n)throw Error("Messaging: `secret` é obrigatório. Use a API key do projeto, por exemplo new Messaging({ secret: process.env.MESSAGING_API_KEY }).");let r=new oe({secret:n,baseUrl:(t.baseUrl??Se(`MESSAGING_BASE_URL`)??`https://api.messaging.rockfeller.com.br`).replace(/\/+$/,``),timeout:t.timeout??3e4,maxRetries:t.maxRetries??2,headers:t.headers??{},fetch:t.fetch??((e,t)=>globalThis.fetch(e,t))});this.messages=new G(r),this.emails=new j(this.messages),this.whatsapp=new Y(this.messages),this.whatsappTemplates=new X(r),this.sms=new K(this.messages),this.webPush=new J(this.messages,r),this.suppressions=new q(r)}};const Ce=[`email`,`whatsapp`,`sms`,`webpush`],we=[`resend`,`unosend`,`twilio`,`meta`,`evolution`],Te=[`normal`,`low`],Ee=[`accepted`,`canceled`,`processing`,`sent`,`delivered`,`complained`,`bounced`,`suppressed`,`failed`],De=[`pending`,`canceled`,`processing`,`sent`,`delivered`,`complained`,`bounced`,`suppressed`,`failed`],Oe=[`delivered`,`complained`],Q=[`bounced`,`suppressed`,`failed`],$=[`canceled`,`delivered`,`complained`,`bounced`,`suppressed`,`failed`];function ke(e){return $.includes(e)}const Ae=[`sent`,`failed`,`unknown`],je=[`email.sent`,`email.delivered`,`email.delivery_delayed`,`email.opened`,`email.clicked`,`email.bounced`,`email.complained`,`email.failed`,`email.suppressed`,`whatsapp.sent`,`whatsapp.delivered`,`whatsapp.read`,`whatsapp.failed`,`sms.sent`,`sms.delivered`,`sms.failed`,`sms.bounced`,`webpush.sent`,`webpush.failed`,`webpush.expired`],Me=[`manual`,`bounce`,`complaint`,`provider_suppressed`],Ne=[`api`,`dashboard`,`automatic`],Pe=[`MARKETING`,`UTILITY`,`AUTHENTICATION`],Fe=[`DRAFT`,`SUBMITTING`,`SUBMISSION_UNKNOWN`,`PENDING`,`APPROVED`,`REJECTED`,`PAUSED`,`DISABLED`,`DELETED`];exports.ATTACHMENT_FILENAME_MAX_LENGTH=255,exports.ATTACHMENT_URL_MAX_LENGTH=o,exports.AuthenticationError=_,exports.BLOCKED_ATTACHMENT_EXTENSIONS=d,exports.ConnectionError=S,exports.DEFAULT_BASE_URL=`https://api.messaging.rockfeller.com.br`,exports.DEFAULT_MAX_RETRIES=2,exports.DEFAULT_TIMEOUT_MS=3e4,exports.EMAIL_ATTACHMENTS_MAX_COUNT=10,exports.EMAIL_ATTACHMENTS_MAX_TOTAL_BYTES=n,exports.EMAIL_ATTACHMENT_CONTENT_TYPES=u,exports.EMAIL_ATTACHMENT_DISPOSITIONS=c,exports.Emails=j,exports.MESSAGE_ATTACHMENT_SOURCES=s,exports.MESSAGE_ATTEMPT_OUTCOMES=Ae,exports.MESSAGE_BATCH_MAX_SIZE=100,exports.MESSAGE_BODY_MAX_BYTES=262144,exports.MESSAGE_DELIVERED_STATUSES=Oe,exports.MESSAGE_DELIVERY_STATUSES=De,exports.MESSAGE_DELIVERY_TERMINAL_STATUSES=$,exports.MESSAGE_EVENT_TYPES=je,exports.MESSAGE_JSON_MAX_BYTES=65536,exports.MESSAGE_LIST_DEFAULT_LIMIT=25,exports.MESSAGE_LIST_MAX_LIMIT=100,exports.MESSAGE_PRIORITIES=Te,exports.MESSAGE_STATUSES=Ee,exports.MESSAGE_SUBJECT_MAX_LENGTH=998,exports.MESSAGE_UNDELIVERED_STATUSES=Q,exports.MESSAGING_ERROR_CODES=ee,exports.Messages=G,exports.MessagesPage=M,exports.Messaging=Z,exports.default=Z,exports.MessagingError=h,exports.NotFoundError=y,exports.PROVIDER_CHANNELS=Ce,exports.PROVIDER_IDS=we,exports.PermissionError=v,exports.RECIPIENT_SUPPRESSED_FAILURE_CODE=`RECIPIENT_SUPPRESSED`,exports.RateLimitError=b,exports.SMS_CONTENT_MAX_LENGTH=1600,exports.SUPPRESSION_BATCH_MAX_SIZE=100,exports.SUPPRESSION_LIST_DEFAULT_LIMIT=50,exports.SUPPRESSION_LIST_MAX_LIMIT=100,exports.SUPPRESSION_NOTE_MAX_LENGTH=500,exports.SUPPRESSION_REASONS=Me,exports.SUPPRESSION_SOURCES=Ne,exports.ServerError=x,exports.Sms=K,exports.Suppressions=q,exports.TimeoutError=C,exports.VERSION=A,exports.ValidationError=g,exports.WHATSAPP_ATTACHMENTS_MAX_COUNT=1,exports.WHATSAPP_CAPTION_MAX_LENGTH=a,exports.WHATSAPP_IMAGE_MAX_BYTES=r,exports.WHATSAPP_MEDIA_KINDS=f,exports.WHATSAPP_MEDIA_MAX_BYTES=i,exports.WHATSAPP_MEDIA_MAX_BYTES_BY_KIND=m,exports.WHATSAPP_MEDIA_TYPES=p,exports.WHATSAPP_TEMPLATE_CATEGORIES=Pe,exports.WHATSAPP_TEMPLATE_STATUSES=Fe,exports.WebPush=J,exports.WhatsApp=Y,exports.WhatsAppTemplates=X,exports.failure=k,exports.isMessagingError=w,exports.isTerminalDeliveryStatus=ke,exports.success=O;
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("../version-BMXokpna.cjs"),t=1048576,n=20*t,r=5*t,i=10*t,a=1024,o=2048,s=[`upload`,`url`],c=[`attachment`,`inline`],l=[`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/vnd.ms-powerpoint`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`],u=[`application/pdf`,`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`text/csv`,`text/plain`,...l,`application/vnd.oasis.opendocument.text`,`application/vnd.oasis.opendocument.spreadsheet`,`application/zip`,`text/calendar`],d=/* @__PURE__ */ `apk.app.bat.cmd.com.cpl.dll.dmg.exe.hta.jar.js.jse.lnk.msi.msp.pif.ps1.reg.scr.sh.vb.vbe.vbs.wsf.wsh`.split(`.`),f=[`image`,`video`,`audio`,`document`],p={image:[`image/jpeg`,`image/png`],video:[`video/mp4`,`video/3gpp`],audio:[`audio/aac`,`audio/mp4`,`audio/mpeg`,`audio/amr`,`audio/ogg`],document:[`application/pdf`,...l,`text/plain`,`text/csv`,`application/zip`]},m={image:r,video:i,audio:i,document:i},ee=/* @__PURE__ */ `UNAUTHENTICATED.INVALID_API_KEY.ACTIVE_PROJECT_REQUIRED.PROJECT_ROLE_REQUIRED.VALIDATION_ERROR.FROM_DOMAIN_NOT_VERIFIED.SENDER_NOT_FOUND.WHATSAPP_TEMPLATE_NOT_FOUND.WHATSAPP_TEMPLATE_CONFLICT.WHATSAPP_TEMPLATE_PROVIDER_UNSUPPORTED.WHATSAPP_TEMPLATE_SUBMISSION_FAILED.WHATSAPP_TEMPLATE_SYNC_FAILED.WHATSAPP_TEMPLATE_INVALID_STATE.WHATSAPP_TEMPLATE_BODY_CONFLICT.ATTACHMENTS_NOT_SUPPORTED_FOR_CHANNEL.ATTACHMENTS_PROVIDER_TEMPLATE_CONFLICT.ATTACHMENT_INVALID.ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED.ATTACHMENT_TOO_LARGE.ATTACHMENTS_LIMIT_EXCEEDED.ATTACHMENT_URL_NOT_ALLOWED.WHATSAPP_CAPTION_INVALID.PAYLOAD_TOO_LARGE.ATTACHMENT_STORAGE_UNAVAILABLE.ATTACHMENT_STORAGE_NOT_CONFIGURED.ATTACHMENT_EXPIRED.MESSAGE_NOT_FOUND.SUPPRESSION_NOT_FOUND.MESSAGE_NOT_RETRYABLE.MESSAGE_CONTENT_EXPIRED.IDEMPOTENCY_KEY_REUSED.ROUTE_NOT_FOUND.INTERNAL_SERVER_ERROR.RATE_LIMIT_EXCEEDED.CONNECTION_ERROR.TIMEOUT.UNEXPECTED_RESPONSE`.split(`.`);var h=class extends Error{name=`MessagingError`;code;status;errors;constructor(e){super(e.message,{cause:e.cause}),this.code=e.code,this.status=e.status,this.errors=e.errors}get retryable(){return this.status===0||this.status===408||this.status===429||this.status>=500}toJSON(){return{name:this.name,code:this.code,message:this.message,status:this.status,...this.errors?{errors:this.errors}:{}}}},g=class extends h{name=`ValidationError`},_=class extends h{name=`AuthenticationError`},v=class extends h{name=`PermissionError`},y=class extends h{name=`NotFoundError`},b=class extends h{name=`RateLimitError`;retryAfter;constructor(e){super(e),this.retryAfter=e.retryAfter}},x=class extends h{name=`ServerError`},S=class extends h{name=`ConnectionError`},C=class extends h{name=`TimeoutError`};function w(e){return e instanceof h}function T(e){let t={code:e.code,message:e.message,status:e.status,...e.errors?{errors:e.errors}:{}};return e.status===429?new b({...t,...e.retryAfter===void 0?{}:{retryAfter:e.retryAfter}}):e.status>=500?new x(t):e.status===401?new _(t):e.status===403?new v(t):e.status===404?new y(t):e.status===400||e.status===422?new g(t):new h(t)}function te(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!==void 0){if(Array.isArray(r))for(let e of r)t.append(n,String(e));else t.append(n,r instanceof Date?r.toISOString():String(r))}let n=t.toString();return n?`?${n}`:``}const E=8e3,ne=e=>new Promise(t=>setTimeout(t,e));function re(e,t){if(t!==void 0)return Math.min(t*1e3,E);let n=Math.min(500*2**e,E);return Math.round(n*(.5+Math.random()*.5))}function ie(e){if(!e)return;let t=Number(e);if(Number.isFinite(t)&&t>=0)return t;let n=Date.parse(e);if(!Number.isNaN(n))return Math.max(0,Math.round((n-Date.now())/1e3))}function D(e){if(e.length===1)return e[0];let t=AbortSignal.any;if(t)return t(e);let n=new AbortController;for(let t of e){if(t.aborted){n.abort(t.reason);break}t.addEventListener(`abort`,()=>n.abort(t.reason),{once:!0})}return n.signal}function O(e){return{data:e,error:null}}function k(e){return{data:null,error:e}}const A=e.t,ae=`rockdev-messaging-node/${A}`;var oe=class{config;constructor(e){this.config=e}async request(e){let t=`${this.config.baseUrl}/v1${e.path}${e.query?te(e.query):``}`,n=e.method===`GET`||e.idempotencyKey!==void 0?this.config.maxRetries:0,r;for(let i=0;i<=n;i+=1){let a=await this.attempt(t,e);if(a.error===null)return a;if(r=a.error,!a.error.retryable||e.options?.signal?.aborted||i===n)break;await ne(re(i,a.error.retryAfter))}return k(r)}async attempt(e,t){let n=t.options?.timeout??this.config.timeout,r=new AbortController,i=setTimeout(()=>r.abort(),n),a=[r.signal];t.options?.signal&&a.push(t.options.signal);let o;try{o=await this.config.fetch(e,{method:t.method,headers:this.headers(t),signal:D(a),...t.body===void 0?{}:{body:JSON.stringify(t.body)}})}catch(e){return t.options?.signal?.aborted?k(new h({code:`CONNECTION_ERROR`,message:`The request was aborted by the caller.`,status:0,cause:e})):r.signal.aborted?k(new C({code:`TIMEOUT`,message:`The request did not complete within ${n}ms.`,status:0,cause:e})):k(new S({code:`CONNECTION_ERROR`,message:e instanceof Error?e.message:`The request could not reach the Messaging API.`,status:0,cause:e}))}finally{clearTimeout(i)}return this.parse(o)}headers(e){let t=e=>Object.fromEntries(Object.entries(e).filter(([e])=>e.toLowerCase()!==`idempotency-key`));return{accept:`application/json`,authorization:`Bearer ${this.config.secret}`,"user-agent":ae,...e.body===void 0?{}:{"content-type":`application/json`},...t(this.config.headers),...t(e.options?.headers??{}),...e.idempotencyKey===void 0?{}:{"idempotency-key":e.idempotencyKey}}}async parse(e){let t=await e.text().catch(()=>``),n;try{n=t?JSON.parse(t):void 0}catch{n=void 0}if(!e.ok){let t=ie(e.headers.get(`retry-after`));return k(T({code:n?.code??`INTERNAL_SERVER_ERROR`,message:n?.message??`The Messaging API responded with ${e.status}.`,status:e.status,...n?.errors?{errors:n.errors}:{},...t===void 0?{}:{retryAfter:t}}))}return!n||n.data===void 0?k(new h({code:`UNEXPECTED_RESPONSE`,message:`The Messaging API responded without the expected body.`,status:e.status})):O(n.data)}},j=class{messages;constructor(e){this.messages=e}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:typeof n==`string`?{email:n}:n},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:typeof e==`string`?{email:e}:e})),t)}},M=class e{fetchPage;messages;nextCursor;constructor(e,t){this.fetchPage=t,this.messages=e.messages,this.nextCursor=e.nextCursor}get hasMore(){return this.nextCursor!==null}async next(){return this.nextCursor===null?{data:new e({messages:[],nextCursor:null},this.fetchPage),error:null}:this.fetchPage(this.nextCursor)}async*[Symbol.asyncIterator](){let e=this;for(;;){for(let t of e.messages)yield t;if(!e.hasMore)return;let{data:t,error:n}=await e.next();if(n)throw n;e=t}}};function N(e){if(e!==void 0)return e instanceof Date?e.toISOString():e}function se(e){return{status:e.status,channel:e.channel,to:e.to,search:e.search,scheduled:e.scheduled,createdAfter:N(e.createdAfter),createdBefore:N(e.createdBefore),limit:e.limit,cursor:e.cursor}}const P=24576;function ce(e){if(typeof e.toBase64==`function`)return e.toBase64();let t=globalThis.Buffer;if(t)return t.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`);let n=``;for(let t=0;t<e.length;t+=P){let r=e.subarray(t,t+P),i=``;for(let e=0;e<r.length;e+=1)i+=String.fromCharCode(r[e]);n+=btoa(i)}return n}function le(e){let t=e.endsWith(`==`)?2:+!!e.endsWith(`=`);return e.length/4*3-t}function ue(e){return typeof Blob<`u`&&e instanceof Blob}function de(e){return`email`in e&&e.email!==void 0?`email`:`whatsapp`in e&&e.whatsapp!==void 0?`whatsapp`:`sms`in e&&e.sms!==void 0?`sms`:`webpush`}function fe(e){return typeof e==`string`?e.includes(`@`)?{email:e}:{whatsapp:e}:e}function F(e){let t=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(e);if(!t)return null;let[n,r]=[Number(t[1]),Number(t[2])];return n===0||n===10||n===127||n===100&&r>=64&&r<=127||n===169&&r===254||n===172&&r>=16&&r<=31||n===192&&r===168||n===198&&(r===18||r===19)||n>=224}function I(e){if(!e.startsWith(`[`))return null;let t=e.slice(1,-1).toLowerCase(),n=/^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(t);return n?.[1]?F(n[1])??!0:t===`::`||t===`::1`||t.startsWith(`::ffff:`)||/^f[cd]/.test(t)||/^fe[89ab]/.test(t)||t.startsWith(`ff`)}function L(e){try{return new URL(e)}catch{return null}}const R={pdf:`application/pdf`,png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,gif:`image/gif`,webp:`image/webp`,csv:`text/csv`,txt:`text/plain`,doc:`application/msword`,docx:`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,xls:`application/vnd.ms-excel`,xlsx:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,ppt:`application/vnd.ms-powerpoint`,pptx:`application/vnd.openxmlformats-officedocument.presentationml.presentation`,odt:`application/vnd.oasis.opendocument.text`,ods:`application/vnd.oasis.opendocument.spreadsheet`,zip:`application/zip`,ics:`text/calendar`,mp4:`video/mp4`,"3gp":`video/3gpp`,aac:`audio/aac`,m4a:`audio/mp4`,mp3:`audio/mpeg`,amr:`audio/amr`,ogg:`audio/ogg`,opus:`audio/ogg`};function z(e){return(e.split(`;`)[0]??``).trim().toLowerCase()}function B(e){let t=e.lastIndexOf(`.`);return t<=0||t===e.length-1?``:e.slice(t+1).toLowerCase()}function V(e){let t=z(e);for(let e of f)if(p[e].includes(t))return e;return null}function pe(e){return R[B(e.trim())]}const me=/^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*(\s*;.*)?$/i,he=/^[A-Za-z0-9+/]*={0,2}$/,ge=/[/\\\u0000-\u001f\u007f]/;var H=class{code;message;detail;constructor(e,t,n){this.code=e,this.message=t,this.detail=n}};function U(e,t,n=t){throw new H(e,t,n)}function _e(e,t){let n=e=>U(`ATTACHMENT_URL_NOT_ALLOWED`,`The attachment URL is not allowed: ${e}.`,`${t}.url ${e}`);e.length>2048&&n(`must be at most ${o} characters long`);let r=L(e)??n(`must be a valid URL`);r.protocol!==`https:`&&n(`must use https`),(r.username||r.password)&&n(`must not contain credentials`),r.port&&r.port!==`443`&&n(`must use the default port`);let i=r.hostname.toLowerCase().replace(/\.$/,``);(i===`localhost`||i.endsWith(`.localhost`)||i.endsWith(`.local`)||i.endsWith(`.internal`))&&n(`must not point to a local host`),!i.startsWith(`[`)&&!i.includes(`.`)&&n(`must use a fully qualified host name`),(F(i)||I(i))&&n(`must not point to a private address`)}async function ve(e,t){let n=e=>U(`ATTACHMENT_INVALID`,`The attachment is invalid.`,e);typeof e==`object`&&e||n(`${t} must be an object`);let{filename:r,disposition:i,contentId:a}=e;(typeof r!=`string`||r.trim()===``)&&n(`${t}.filename is required`),r.length>255&&n(`${t}.filename must be at most 255 characters long`),ge.test(r)&&n(`${t}.filename must not contain path separators or control characters`);let o=`url`in e&&e.url!==void 0;o===(`content`in e&&e.content!==void 0)&&n(`${t} must have exactly one of url or content`),i!==void 0&&!c.includes(i)&&n(`${t}.disposition must be one of attachment, inline`),a!==void 0&&(typeof a!=`string`||a===``||a.length>255)&&n(`${t}.contentId must be a non-empty string of at most 255 characters`),i===`inline`&&(a??``).trim()===``&&n(`${t}.contentId is required for inline attachments`);let s={...i===void 0?{}:{disposition:i},...a===void 0?{}:{contentId:a}},l=e=>e===void 0||e.trim()===``?n(`${t}.contentType is required`):(me.test(e)||n(`${t}.contentType must be a type/subtype MIME type`),e);if(o){let{url:i}=e;return typeof i==`string`?(_e(i,t),{body:{filename:r,contentType:l(e.contentType),url:i,...s},size:null}):n(`${t}.url must be a string`)}let{content:u}=e,d,f,p;if(typeof u==`string`)u.length%4==0&&he.test(u)||n(`${t}.content must be valid base64`),d=u,f=le(u);else{let e;if(u instanceof Uint8Array)e=u;else if(u instanceof ArrayBuffer)e=new Uint8Array(u);else if(ArrayBuffer.isView(u))e=new Uint8Array(u.buffer,u.byteOffset,u.byteLength);else if(ue(u))p=u.type||void 0,e=new Uint8Array(await u.arrayBuffer());else return n(`${t}.content must be a Uint8Array, ArrayBuffer, Blob or base64 string`);d=ce(e),f=e.byteLength}return{body:{filename:r,contentType:l(e.contentType??p??pe(r)),content:d,...s},size:f}}function ye(e,t,r){if(e===`email`){t.length>10&&U(`ATTACHMENTS_LIMIT_EXCEEDED`,`An email accepts at most 10 attachments.`);let e=0;t.forEach(({body:t,size:n},r)=>{let i=`attachments.${r}`;u.includes(z(t.contentType))||U(`ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED`,`The attachment content type is not allowed for email.`,`${i}.contentType ${z(t.contentType)} is not allowed`),d.includes(B(t.filename.trim()))&&U(`ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED`,`The attachment file extension is not allowed.`,`${i}.filename has a blocked extension`),e+=n??0}),e>20971520&&U(`ATTACHMENT_TOO_LARGE`,`Email attachments must add up to at most ${n} bytes.`);return}t.length>1&&U(`ATTACHMENTS_LIMIT_EXCEEDED`,`A WhatsApp message accepts at most 1 attachment.`);let[i]=t;if(!i)return;let o=`attachments.0`;(i.body.disposition!==void 0||i.body.contentId!==void 0)&&U(`ATTACHMENT_INVALID`,`The attachment is invalid.`,`${o}.disposition and contentId are email-only`);let s=V(i.body.contentType);s||U(`ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED`,`The attachment content type is not allowed for WhatsApp.`,`${o}.contentType ${z(i.body.contentType)} is not allowed`);let c=m[s];i.size!==null&&i.size>c&&U(`ATTACHMENT_TOO_LARGE`,`WhatsApp ${s} attachments must be at most ${c} bytes.`),r!==void 0&&s===`audio`&&U(`WHATSAPP_CAPTION_INVALID`,`WhatsApp audio does not accept a caption.`,`content must be empty for audio attachments`),r!==void 0&&r.length>1024&&U(`WHATSAPP_CAPTION_INVALID`,`A WhatsApp caption must be at most ${a} characters long.`,`content must be at most ${a} characters long`)}async function be(e,t,n=``){try{let n=de(e.to);n!==`email`&&n!==`whatsapp`&&U(`ATTACHMENTS_NOT_SUPPORTED_FOR_CHANNEL`,`Attachments are not supported for the ${n} channel.`),e.providerTemplate!==void 0&&U(`ATTACHMENTS_PROVIDER_TEMPLATE_CONFLICT`,`Attachments cannot be combined with providerTemplate.`),Array.isArray(t)||U(`ATTACHMENT_INVALID`,`The attachment is invalid.`,`attachments must be an array`);let r=[];for(let[e,n]of t.entries())r.push(await ve(n,`attachments.${e}`));return ye(n,r,e.content),O(r.map(({body:e})=>e))}catch(e){if(!(e instanceof H))throw e;return k(new g({code:e.code,message:e.message,status:400,errors:[`${n}${e.detail}`]}))}}function xe(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}async function W(e,t=``){let{to:n,sendAt:r,attachments:i,...a}=e,{idempotencyKey:o,...s}=a,c=fe(n),l;if(i!==void 0&&i.length>0){let e=await be({to:c,content:s.content,providerTemplate:s.providerTemplate},i,t);if(e.error)return k(e.error);l=e.data}return O(xe({...s,to:c,sendAt:N(r),attachments:l}))}var G=class{http;constructor(e){this.http=e}async send(e,t){let n=await W(e);return n.error?k(n.error):this.http.request({method:`POST`,path:`/messages`,body:n.data,...e.idempotencyKey===void 0?{}:{idempotencyKey:e.idempotencyKey},...t?{options:t}:{}})}async batch(e,t){let{idempotencyKey:n,...r}=t??{},i=[];for(let[t,n]of e.entries()){let e=await W(n,`${t}.`);if(e.error)return k(e.error);i.push(e.data)}return this.http.request({method:`POST`,path:`/messages/batch`,body:i,...n===void 0?{}:{idempotencyKey:n},...t?{options:r}:{}})}async create(e,t){return this.send(e,t)}async retry(e,t,n){return this.http.request({method:`POST`,path:`/messages/${encodeURIComponent(e)}/retry`,idempotencyKey:t.idempotencyKey,...n?{options:n}:{}})}async get(e,t){return this.http.request({method:`GET`,path:`/messages/${encodeURIComponent(e)}`,...t?{options:t}:{}})}async retrieve(e,t){return this.get(e,t)}async list(e={},t){let{data:n,error:r}=await this.http.request({method:`GET`,path:`/messages`,query:se(e),...t?{options:t}:{}});return r?{data:null,error:r}:{data:new M(n,n=>this.list({...e,cursor:n},t)),error:null}}},K=class{messages;constructor(e){this.messages=e}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:typeof n==`string`?{sms:n}:n},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:typeof e==`string`?{sms:e}:e})),t)}},q=class{http;constructor(e){this.http=e}create(e,t){return this.http.request({method:`POST`,path:`/suppressions`,body:e,...t?{options:t}:{}})}batch(e,t){return this.http.request({method:`POST`,path:`/suppressions/batch`,body:e,...t?{options:t}:{}})}get(e,t){return this.http.request({method:`GET`,path:`/suppressions/${encodeURIComponent(e)}`,...t?{options:t}:{}})}list(e={},t){return this.http.request({method:`GET`,path:`/suppressions`,query:{email:e.email,reason:e.reason,limit:e.limit,cursor:e.cursor},...t?{options:t}:{}})}delete(e,t){return this.http.request({method:`DELETE`,path:`/suppressions/${encodeURIComponent(e)}`,...t?{options:t}:{}})}batchDelete(e,t){return this.http.request({method:`POST`,path:`/suppressions/batch/delete`,body:e,...t?{options:t}:{}})}},J=class{messages;http;constructor(e,t){this.messages=e,this.http=t}async createSubscriptionToken(e,t){return this.http.request({method:`POST`,path:`/webpush/subscription-tokens`,body:e,...t?{options:t}:{}})}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:{webpush:typeof n==`string`?{recipientId:n}:n}},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:{webpush:typeof e==`string`?{recipientId:e}:e}})),t)}},Y=class{messages;constructor(e){this.messages=e}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:typeof n==`string`?{whatsapp:n}:n},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:typeof e==`string`?{whatsapp:e}:e})),t)}},X=class{http;constructor(e){this.http=e}list(e={},t){return this.http.request({method:`GET`,path:`/whatsapp-templates`,query:{senderId:e.senderId},...t?{options:t}:{}})}get(e,t){return this.http.request({method:`GET`,path:`/whatsapp-templates/${encodeURIComponent(e)}`,...t?{options:t}:{}})}create(e,t){return this.http.request({method:`POST`,path:`/whatsapp-templates`,body:e,...t?{options:t}:{}})}update(e,t,n){return this.http.request({method:`PATCH`,path:`/whatsapp-templates/${encodeURIComponent(e)}`,body:t,...n?{options:n}:{}})}submit(e,t,n){return this.http.request({method:`POST`,path:`/whatsapp-templates/${encodeURIComponent(e)}/submit`,body:t,...n?{options:n}:{}})}sync(e,t){return this.http.request({method:`POST`,path:`/whatsapp-templates/sync`,body:e,...t?{options:t}:{}})}};function Se(e){return(globalThis.process?.env?.[e])?.trim()||void 0}var Z=class{messages;emails;whatsapp;whatsappTemplates;sms;webPush;suppressions;constructor(e){let t=typeof e==`string`?{secret:e}:e,n=t.secret?.trim();if(!n)throw Error("Messaging: `secret` é obrigatório. Use a API key do projeto, por exemplo new Messaging({ secret: process.env.MESSAGING_API_KEY }).");let r=new oe({secret:n,baseUrl:(t.baseUrl??Se(`MESSAGING_BASE_URL`)??`https://api.messaging.rockfeller.com.br`).replace(/\/+$/,``),timeout:t.timeout??3e4,maxRetries:t.maxRetries??2,headers:t.headers??{},fetch:t.fetch??((e,t)=>globalThis.fetch(e,t))});this.messages=new G(r),this.emails=new j(this.messages),this.whatsapp=new Y(this.messages),this.whatsappTemplates=new X(r),this.sms=new K(this.messages),this.webPush=new J(this.messages,r),this.suppressions=new q(r)}};const Ce=[`email`,`whatsapp`,`sms`,`webpush`],we=[`resend`,`unosend`,`twilio`,`meta`,`evolution`],Te=[`normal`,`low`],Ee=[`accepted`,`canceled`,`processing`,`sent`,`delivered`,`complained`,`bounced`,`suppressed`,`failed`],De=[`pending`,`canceled`,`processing`,`sent`,`delivered`,`complained`,`bounced`,`suppressed`,`failed`],Oe=[`delivered`,`complained`],Q=[`bounced`,`suppressed`,`failed`],$=[`canceled`,`delivered`,`complained`,`bounced`,`suppressed`,`failed`];function ke(e){return $.includes(e)}const Ae=[`sent`,`failed`,`unknown`],je=[`email.sent`,`email.delivered`,`email.delivery_delayed`,`email.opened`,`email.clicked`,`email.bounced`,`email.complained`,`email.failed`,`email.suppressed`,`whatsapp.sent`,`whatsapp.delivered`,`whatsapp.read`,`whatsapp.failed`,`sms.sent`,`sms.delivered`,`sms.failed`,`sms.bounced`,`webpush.sent`,`webpush.failed`,`webpush.expired`],Me=[`manual`,`bounce`,`complaint`,`provider_suppressed`],Ne=[`api`,`dashboard`,`automatic`],Pe=[`MARKETING`,`UTILITY`,`AUTHENTICATION`],Fe=[`DRAFT`,`SUBMITTING`,`SUBMISSION_UNKNOWN`,`PENDING`,`APPROVED`,`REJECTED`,`PAUSED`,`DISABLED`,`DELETED`];exports.ATTACHMENT_FILENAME_MAX_LENGTH=255,exports.ATTACHMENT_URL_MAX_LENGTH=o,exports.AuthenticationError=_,exports.BLOCKED_ATTACHMENT_EXTENSIONS=d,exports.ConnectionError=S,exports.DEFAULT_BASE_URL=`https://api.messaging.rockfeller.com.br`,exports.DEFAULT_MAX_RETRIES=2,exports.DEFAULT_TIMEOUT_MS=3e4,exports.EMAIL_ATTACHMENTS_MAX_COUNT=10,exports.EMAIL_ATTACHMENTS_MAX_TOTAL_BYTES=n,exports.EMAIL_ATTACHMENT_CONTENT_TYPES=u,exports.EMAIL_ATTACHMENT_DISPOSITIONS=c,exports.Emails=j,exports.MESSAGE_ATTACHMENT_SOURCES=s,exports.MESSAGE_ATTEMPT_OUTCOMES=Ae,exports.MESSAGE_BATCH_MAX_SIZE=100,exports.MESSAGE_BODY_MAX_BYTES=262144,exports.MESSAGE_DELIVERED_STATUSES=Oe,exports.MESSAGE_DELIVERY_STATUSES=De,exports.MESSAGE_DELIVERY_TERMINAL_STATUSES=$,exports.MESSAGE_EVENT_TYPES=je,exports.MESSAGE_JSON_MAX_BYTES=65536,exports.MESSAGE_LIST_DEFAULT_LIMIT=25,exports.MESSAGE_LIST_MAX_LIMIT=100,exports.MESSAGE_PRIORITIES=Te,exports.MESSAGE_STATUSES=Ee,exports.MESSAGE_SUBJECT_MAX_LENGTH=998,exports.MESSAGE_UNDELIVERED_STATUSES=Q,exports.MESSAGING_ERROR_CODES=ee,exports.Messages=G,exports.MessagesPage=M,exports.Messaging=Z,exports.default=Z,exports.MessagingError=h,exports.NotFoundError=y,exports.PROVIDER_CHANNELS=Ce,exports.PROVIDER_IDS=we,exports.PermissionError=v,exports.RECIPIENT_SUPPRESSED_FAILURE_CODE=`RECIPIENT_SUPPRESSED`,exports.RateLimitError=b,exports.SMS_CONTENT_MAX_LENGTH=1600,exports.SUPPRESSION_BATCH_MAX_SIZE=100,exports.SUPPRESSION_LIST_DEFAULT_LIMIT=50,exports.SUPPRESSION_LIST_MAX_LIMIT=100,exports.SUPPRESSION_NOTE_MAX_LENGTH=500,exports.SUPPRESSION_REASONS=Me,exports.SUPPRESSION_SOURCES=Ne,exports.ServerError=x,exports.Sms=K,exports.Suppressions=q,exports.TimeoutError=C,exports.VERSION=A,exports.ValidationError=g,exports.WHATSAPP_ATTACHMENTS_MAX_COUNT=1,exports.WHATSAPP_CAPTION_MAX_LENGTH=a,exports.WHATSAPP_IMAGE_MAX_BYTES=r,exports.WHATSAPP_MEDIA_KINDS=f,exports.WHATSAPP_MEDIA_MAX_BYTES=i,exports.WHATSAPP_MEDIA_MAX_BYTES_BY_KIND=m,exports.WHATSAPP_MEDIA_TYPES=p,exports.WHATSAPP_TEMPLATE_CATEGORIES=Pe,exports.WHATSAPP_TEMPLATE_STATUSES=Fe,exports.WebPush=J,exports.WhatsApp=Y,exports.WhatsAppTemplates=X,exports.failure=k,exports.isMessagingError=w,exports.isTerminalDeliveryStatus=ke,exports.success=O;
|
|
@@ -1914,5 +1914,5 @@ export declare const SUPPRESSION_NOTE_MAX_LENGTH = 500;
|
|
|
1914
1914
|
/** Limite do `subject`, em caracteres. */
|
|
1915
1915
|
export declare const MESSAGE_SUBJECT_MAX_LENGTH = 998;
|
|
1916
1916
|
/** Versão do pacote `franchising`, a mesma do `package.json`. */
|
|
1917
|
-
export declare const VERSION = "0.
|
|
1917
|
+
export declare const VERSION = "0.8.0";
|
|
1918
1918
|
export { type AcceptedBatchMessage, type AcceptedDelivery, type AcceptedMessage, type AcceptedMessageRetry, type AcceptedWebPushDelivery, type AttachmentContent, type AttachmentContentInput, type AttachmentInput, type AttachmentUrlInput, type BatchCreateSuppressionsOptions, type BatchCreateSuppressionsPayload, type BatchDeleteSuppressionsOptions, type BatchDeleteSuppressionsPayload, type BatchRequestOptions, type BatchSendEmailInput, type BatchSendMessageOptions, type BatchSendSmsInput, type BatchSendWebPushInput, type BatchSendWhatsAppInput, type CreateSuppressionOptions, type CreateWebPushSubscriptionTokenInput, type CreateWhatsAppTemplateOptions, type DeletedSuppression, type EmailAttachmentDisposition, type EmailAttachmentInput, type EmailAttachmentOptions, type EmailDestination, type FetchLike, type IsoDateTime, type JsonObject, type ListMessagesOptions, type ListSuppressionsOptions, type ListedMessage, type ListedMessageChannel, type LooseString, type Message, type MessageAttachment, type MessageAttachmentSource, type MessageAttempt, type MessageAttemptOutcome, type MessageChannel, type MessageDeliveryStatus, type MessageDestination, type MessageEvent, type MessageEventType, type MessageListPayload, type MessagePriority, type MessageRetry, type MessageStatus, Messaging as default, type MessagingConfig, type MessagingErrorCode, type MessagingErrorOptions, type ProviderChannel, type ProviderId, type RequestOptions, type Result, type RetryMessageOptions, type SendEmailInput, type SendEmailOptions, type SendMessageOptions, type SendSmsInput, type SendSmsOptions, type SendWebPushInput, type SendWebPushOptions, type SendWhatsAppInput, type SendWhatsAppOptions, type SmsDestination, type SubmitWhatsAppTemplateOptions, type Suppression, type SuppressionListPayload, type SuppressionReason, type SuppressionSource, type UpdateWhatsAppTemplateOptions, type WebPushDestination, type WebPushSubscriptionToken, type WebPushTarget, type WhatsAppAttachmentInput, type WhatsAppAuthenticationTemplateComponent, type WhatsAppDestination, type WhatsAppMediaKind, type WhatsAppProviderTemplate, type WhatsAppTemplate, type WhatsAppTemplateCategory, type WhatsAppTemplateComponent, type WhatsAppTemplateStatus };
|
|
@@ -1914,5 +1914,5 @@ export declare const SUPPRESSION_NOTE_MAX_LENGTH = 500;
|
|
|
1914
1914
|
/** Limite do `subject`, em caracteres. */
|
|
1915
1915
|
export declare const MESSAGE_SUBJECT_MAX_LENGTH = 998;
|
|
1916
1916
|
/** Versão do pacote `franchising`, a mesma do `package.json`. */
|
|
1917
|
-
export declare const VERSION = "0.
|
|
1917
|
+
export declare const VERSION = "0.8.0";
|
|
1918
1918
|
export { type AcceptedBatchMessage, type AcceptedDelivery, type AcceptedMessage, type AcceptedMessageRetry, type AcceptedWebPushDelivery, type AttachmentContent, type AttachmentContentInput, type AttachmentInput, type AttachmentUrlInput, type BatchCreateSuppressionsOptions, type BatchCreateSuppressionsPayload, type BatchDeleteSuppressionsOptions, type BatchDeleteSuppressionsPayload, type BatchRequestOptions, type BatchSendEmailInput, type BatchSendMessageOptions, type BatchSendSmsInput, type BatchSendWebPushInput, type BatchSendWhatsAppInput, type CreateSuppressionOptions, type CreateWebPushSubscriptionTokenInput, type CreateWhatsAppTemplateOptions, type DeletedSuppression, type EmailAttachmentDisposition, type EmailAttachmentInput, type EmailAttachmentOptions, type EmailDestination, type FetchLike, type IsoDateTime, type JsonObject, type ListMessagesOptions, type ListSuppressionsOptions, type ListedMessage, type ListedMessageChannel, type LooseString, type Message, type MessageAttachment, type MessageAttachmentSource, type MessageAttempt, type MessageAttemptOutcome, type MessageChannel, type MessageDeliveryStatus, type MessageDestination, type MessageEvent, type MessageEventType, type MessageListPayload, type MessagePriority, type MessageRetry, type MessageStatus, Messaging as default, type MessagingConfig, type MessagingErrorCode, type MessagingErrorOptions, type ProviderChannel, type ProviderId, type RequestOptions, type Result, type RetryMessageOptions, type SendEmailInput, type SendEmailOptions, type SendMessageOptions, type SendSmsInput, type SendSmsOptions, type SendWebPushInput, type SendWebPushOptions, type SendWhatsAppInput, type SendWhatsAppOptions, type SmsDestination, type SubmitWhatsAppTemplateOptions, type Suppression, type SuppressionListPayload, type SuppressionReason, type SuppressionSource, type UpdateWhatsAppTemplateOptions, type WebPushDestination, type WebPushSubscriptionToken, type WebPushTarget, type WhatsAppAttachmentInput, type WhatsAppAuthenticationTemplateComponent, type WhatsAppDestination, type WhatsAppMediaKind, type WhatsAppProviderTemplate, type WhatsAppTemplate, type WhatsAppTemplateCategory, type WhatsAppTemplateComponent, type WhatsAppTemplateStatus };
|
package/dist/messaging/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"../version-Cm1EJ-YK.js";const t=1048576,n=10,r=20*t,i=1,a=5*t,o=10*t,s=1024,c=2048,l=255,u=[`upload`,`url`],d=[`attachment`,`inline`],f=[`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/vnd.ms-powerpoint`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`],p=[`application/pdf`,`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`text/csv`,`text/plain`,...f,`application/vnd.oasis.opendocument.text`,`application/vnd.oasis.opendocument.spreadsheet`,`application/zip`,`text/calendar`],m=/* @__PURE__ */ `apk.app.bat.cmd.com.cpl.dll.dmg.exe.hta.jar.js.jse.lnk.msi.msp.pif.ps1.reg.scr.sh.vb.vbe.vbs.wsf.wsh`.split(`.`),h=[`image`,`video`,`audio`,`document`],g={image:[`image/jpeg`,`image/png`],video:[`video/mp4`,`video/3gpp`],audio:[`audio/aac`,`audio/mp4`,`audio/mpeg`,`audio/amr`,`audio/ogg`],document:[`application/pdf`,...f,`text/plain`,`text/csv`,`application/zip`]},_={image:a,video:o,audio:o,document:o},ee=/* @__PURE__ */ `UNAUTHENTICATED.INVALID_API_KEY.ACTIVE_PROJECT_REQUIRED.PROJECT_ROLE_REQUIRED.VALIDATION_ERROR.FROM_DOMAIN_NOT_VERIFIED.SENDER_NOT_FOUND.WHATSAPP_TEMPLATE_NOT_FOUND.WHATSAPP_TEMPLATE_CONFLICT.WHATSAPP_TEMPLATE_PROVIDER_UNSUPPORTED.WHATSAPP_TEMPLATE_SUBMISSION_FAILED.WHATSAPP_TEMPLATE_SYNC_FAILED.WHATSAPP_TEMPLATE_INVALID_STATE.WHATSAPP_TEMPLATE_BODY_CONFLICT.ATTACHMENTS_NOT_SUPPORTED_FOR_CHANNEL.ATTACHMENTS_PROVIDER_TEMPLATE_CONFLICT.ATTACHMENT_INVALID.ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED.ATTACHMENT_TOO_LARGE.ATTACHMENTS_LIMIT_EXCEEDED.ATTACHMENT_URL_NOT_ALLOWED.WHATSAPP_CAPTION_INVALID.PAYLOAD_TOO_LARGE.ATTACHMENT_STORAGE_UNAVAILABLE.ATTACHMENT_STORAGE_NOT_CONFIGURED.ATTACHMENT_EXPIRED.MESSAGE_NOT_FOUND.SUPPRESSION_NOT_FOUND.MESSAGE_NOT_RETRYABLE.MESSAGE_CONTENT_EXPIRED.IDEMPOTENCY_KEY_REUSED.ROUTE_NOT_FOUND.INTERNAL_SERVER_ERROR.RATE_LIMIT_EXCEEDED.CONNECTION_ERROR.TIMEOUT.UNEXPECTED_RESPONSE`.split(`.`);var v=class extends Error{name=`MessagingError`;code;status;errors;constructor(e){super(e.message,{cause:e.cause}),this.code=e.code,this.status=e.status,this.errors=e.errors}get retryable(){return this.status===0||this.status===408||this.status===429||this.status>=500}toJSON(){return{name:this.name,code:this.code,message:this.message,status:this.status,...this.errors?{errors:this.errors}:{}}}},y=class extends v{name=`ValidationError`},b=class extends v{name=`AuthenticationError`},x=class extends v{name=`PermissionError`},S=class extends v{name=`NotFoundError`},C=class extends v{name=`RateLimitError`;retryAfter;constructor(e){super(e),this.retryAfter=e.retryAfter}},w=class extends v{name=`ServerError`},T=class extends v{name=`ConnectionError`},E=class extends v{name=`TimeoutError`};function te(e){return e instanceof v}function ne(e){let t={code:e.code,message:e.message,status:e.status,...e.errors?{errors:e.errors}:{}};return e.status===429?new C({...t,...e.retryAfter===void 0?{}:{retryAfter:e.retryAfter}}):e.status>=500?new w(t):e.status===401?new b(t):e.status===403?new x(t):e.status===404?new S(t):e.status===400||e.status===422?new y(t):new v(t)}function re(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!==void 0){if(Array.isArray(r))for(let e of r)t.append(n,String(e));else t.append(n,r instanceof Date?r.toISOString():String(r))}let n=t.toString();return n?`?${n}`:``}const D=8e3,ie=e=>new Promise(t=>setTimeout(t,e));function ae(e,t){if(t!==void 0)return Math.min(t*1e3,D);let n=Math.min(500*2**e,D);return Math.round(n*(.5+Math.random()*.5))}function oe(e){if(!e)return;let t=Number(e);if(Number.isFinite(t)&&t>=0)return t;let n=Date.parse(e);if(!Number.isNaN(n))return Math.max(0,Math.round((n-Date.now())/1e3))}function O(e){if(e.length===1)return e[0];let t=AbortSignal.any;if(t)return t(e);let n=new AbortController;for(let t of e){if(t.aborted){n.abort(t.reason);break}t.addEventListener(`abort`,()=>n.abort(t.reason),{once:!0})}return n.signal}function k(e){return{data:e,error:null}}function A(e){return{data:null,error:e}}const j=e,se=`rockdev-messaging-node/${j}`,ce=3e4,le=2;var ue=class{config;constructor(e){this.config=e}async request(e){let t=`${this.config.baseUrl}/v1${e.path}${e.query?re(e.query):``}`,n=e.method===`GET`||e.idempotencyKey!==void 0?this.config.maxRetries:0,r;for(let i=0;i<=n;i+=1){let a=await this.attempt(t,e);if(a.error===null)return a;if(r=a.error,!a.error.retryable||e.options?.signal?.aborted||i===n)break;await ie(ae(i,a.error.retryAfter))}return A(r)}async attempt(e,t){let n=t.options?.timeout??this.config.timeout,r=new AbortController,i=setTimeout(()=>r.abort(),n),a=[r.signal];t.options?.signal&&a.push(t.options.signal);let o;try{o=await this.config.fetch(e,{method:t.method,headers:this.headers(t),signal:O(a),...t.body===void 0?{}:{body:JSON.stringify(t.body)}})}catch(e){return t.options?.signal?.aborted?A(new v({code:`CONNECTION_ERROR`,message:`The request was aborted by the caller.`,status:0,cause:e})):r.signal.aborted?A(new E({code:`TIMEOUT`,message:`The request did not complete within ${n}ms.`,status:0,cause:e})):A(new T({code:`CONNECTION_ERROR`,message:e instanceof Error?e.message:`The request could not reach the Messaging API.`,status:0,cause:e}))}finally{clearTimeout(i)}return this.parse(o)}headers(e){let t=e=>Object.fromEntries(Object.entries(e).filter(([e])=>e.toLowerCase()!==`idempotency-key`));return{accept:`application/json`,authorization:`Bearer ${this.config.secret}`,"user-agent":se,...e.body===void 0?{}:{"content-type":`application/json`},...t(this.config.headers),...t(e.options?.headers??{}),...e.idempotencyKey===void 0?{}:{"idempotency-key":e.idempotencyKey}}}async parse(e){let t=await e.text().catch(()=>``),n;try{n=t?JSON.parse(t):void 0}catch{n=void 0}if(!e.ok){let t=oe(e.headers.get(`retry-after`));return A(ne({code:n?.code??`INTERNAL_SERVER_ERROR`,message:n?.message??`The Messaging API responded with ${e.status}.`,status:e.status,...n?.errors?{errors:n.errors}:{},...t===void 0?{}:{retryAfter:t}}))}return!n||n.data===void 0?A(new v({code:`UNEXPECTED_RESPONSE`,message:`The Messaging API responded without the expected body.`,status:e.status})):k(n.data)}},M=class{messages;constructor(e){this.messages=e}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:typeof n==`string`?{email:n}:n},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:typeof e==`string`?{email:e}:e})),t)}},N=class e{fetchPage;messages;nextCursor;constructor(e,t){this.fetchPage=t,this.messages=e.messages,this.nextCursor=e.nextCursor}get hasMore(){return this.nextCursor!==null}async next(){return this.nextCursor===null?{data:new e({messages:[],nextCursor:null},this.fetchPage),error:null}:this.fetchPage(this.nextCursor)}async*[Symbol.asyncIterator](){let e=this;for(;;){for(let t of e.messages)yield t;if(!e.hasMore)return;let{data:t,error:n}=await e.next();if(n)throw n;e=t}}};function P(e){if(e!==void 0)return e instanceof Date?e.toISOString():e}function de(e){return{status:e.status,channel:e.channel,to:e.to,search:e.search,scheduled:e.scheduled,createdAfter:P(e.createdAfter),createdBefore:P(e.createdBefore),limit:e.limit,cursor:e.cursor}}const F=24576;function fe(e){if(typeof e.toBase64==`function`)return e.toBase64();let t=globalThis.Buffer;if(t)return t.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`);let n=``;for(let t=0;t<e.length;t+=F){let r=e.subarray(t,t+F),i=``;for(let e=0;e<r.length;e+=1)i+=String.fromCharCode(r[e]);n+=btoa(i)}return n}function pe(e){let t=e.endsWith(`==`)?2:+!!e.endsWith(`=`);return e.length/4*3-t}function me(e){return typeof Blob<`u`&&e instanceof Blob}function I(e){return`email`in e&&e.email!==void 0?`email`:`whatsapp`in e&&e.whatsapp!==void 0?`whatsapp`:`sms`in e&&e.sms!==void 0?`sms`:`webpush`}function L(e){return typeof e==`string`?e.includes(`@`)?{email:e}:{whatsapp:e}:e}function R(e){let t=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(e);if(!t)return null;let[n,r]=[Number(t[1]),Number(t[2])];return n===0||n===10||n===127||n===100&&r>=64&&r<=127||n===169&&r===254||n===172&&r>=16&&r<=31||n===192&&r===168||n===198&&(r===18||r===19)||n>=224}function z(e){if(!e.startsWith(`[`))return null;let t=e.slice(1,-1).toLowerCase(),n=/^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(t);return n?.[1]?R(n[1])??!0:t===`::`||t===`::1`||t.startsWith(`::ffff:`)||/^f[cd]/.test(t)||/^fe[89ab]/.test(t)||t.startsWith(`ff`)}function he(e){try{return new URL(e)}catch{return null}}const ge={pdf:`application/pdf`,png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,gif:`image/gif`,webp:`image/webp`,csv:`text/csv`,txt:`text/plain`,doc:`application/msword`,docx:`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,xls:`application/vnd.ms-excel`,xlsx:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,ppt:`application/vnd.ms-powerpoint`,pptx:`application/vnd.openxmlformats-officedocument.presentationml.presentation`,odt:`application/vnd.oasis.opendocument.text`,ods:`application/vnd.oasis.opendocument.spreadsheet`,zip:`application/zip`,ics:`text/calendar`,mp4:`video/mp4`,"3gp":`video/3gpp`,aac:`audio/aac`,m4a:`audio/mp4`,mp3:`audio/mpeg`,amr:`audio/amr`,ogg:`audio/ogg`,opus:`audio/ogg`};function B(e){return(e.split(`;`)[0]??``).trim().toLowerCase()}function V(e){let t=e.lastIndexOf(`.`);return t<=0||t===e.length-1?``:e.slice(t+1).toLowerCase()}function _e(e){let t=B(e);for(let e of h)if(g[e].includes(t))return e;return null}function ve(e){return ge[V(e.trim())]}const ye=/^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*(\s*;.*)?$/i,be=/^[A-Za-z0-9+/]*={0,2}$/,xe=/[/\\\u0000-\u001f\u007f]/;var H=class{code;message;detail;constructor(e,t,n){this.code=e,this.message=t,this.detail=n}};function U(e,t,n=t){throw new H(e,t,n)}function Se(e,t){let n=e=>U(`ATTACHMENT_URL_NOT_ALLOWED`,`The attachment URL is not allowed: ${e}.`,`${t}.url ${e}`);e.length>2048&&n(`must be at most ${c} characters long`);let r=he(e)??n(`must be a valid URL`);r.protocol!==`https:`&&n(`must use https`),(r.username||r.password)&&n(`must not contain credentials`),r.port&&r.port!==`443`&&n(`must use the default port`);let i=r.hostname.toLowerCase().replace(/\.$/,``);(i===`localhost`||i.endsWith(`.localhost`)||i.endsWith(`.local`)||i.endsWith(`.internal`))&&n(`must not point to a local host`),!i.startsWith(`[`)&&!i.includes(`.`)&&n(`must use a fully qualified host name`),(R(i)||z(i))&&n(`must not point to a private address`)}async function Ce(e,t){let n=e=>U(`ATTACHMENT_INVALID`,`The attachment is invalid.`,e);typeof e==`object`&&e||n(`${t} must be an object`);let{filename:r,disposition:i,contentId:a}=e;(typeof r!=`string`||r.trim()===``)&&n(`${t}.filename is required`),r.length>255&&n(`${t}.filename must be at most 255 characters long`),xe.test(r)&&n(`${t}.filename must not contain path separators or control characters`);let o=`url`in e&&e.url!==void 0;o===(`content`in e&&e.content!==void 0)&&n(`${t} must have exactly one of url or content`),i!==void 0&&!d.includes(i)&&n(`${t}.disposition must be one of attachment, inline`),a!==void 0&&(typeof a!=`string`||a===``||a.length>255)&&n(`${t}.contentId must be a non-empty string of at most 255 characters`),i===`inline`&&(a??``).trim()===``&&n(`${t}.contentId is required for inline attachments`);let s={...i===void 0?{}:{disposition:i},...a===void 0?{}:{contentId:a}},c=e=>e===void 0||e.trim()===``?n(`${t}.contentType is required`):(ye.test(e)||n(`${t}.contentType must be a type/subtype MIME type`),e);if(o){let{url:i}=e;return typeof i==`string`?(Se(i,t),{body:{filename:r,contentType:c(e.contentType),url:i,...s},size:null}):n(`${t}.url must be a string`)}let{content:l}=e,u,f,p;if(typeof l==`string`)l.length%4==0&&be.test(l)||n(`${t}.content must be valid base64`),u=l,f=pe(l);else{let e;if(l instanceof Uint8Array)e=l;else if(l instanceof ArrayBuffer)e=new Uint8Array(l);else if(ArrayBuffer.isView(l))e=new Uint8Array(l.buffer,l.byteOffset,l.byteLength);else if(me(l))p=l.type||void 0,e=new Uint8Array(await l.arrayBuffer());else return n(`${t}.content must be a Uint8Array, ArrayBuffer, Blob or base64 string`);u=fe(e),f=e.byteLength}return{body:{filename:r,contentType:c(e.contentType??p??ve(r)),content:u,...s},size:f}}function we(e,t,n){if(e===`email`){t.length>10&&U(`ATTACHMENTS_LIMIT_EXCEEDED`,`An email accepts at most 10 attachments.`);let e=0;t.forEach(({body:t,size:n},r)=>{let i=`attachments.${r}`;p.includes(B(t.contentType))||U(`ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED`,`The attachment content type is not allowed for email.`,`${i}.contentType ${B(t.contentType)} is not allowed`),m.includes(V(t.filename.trim()))&&U(`ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED`,`The attachment file extension is not allowed.`,`${i}.filename has a blocked extension`),e+=n??0}),e>20971520&&U(`ATTACHMENT_TOO_LARGE`,`Email attachments must add up to at most ${r} bytes.`);return}t.length>1&&U(`ATTACHMENTS_LIMIT_EXCEEDED`,`A WhatsApp message accepts at most 1 attachment.`);let[i]=t;if(!i)return;let a=`attachments.0`;(i.body.disposition!==void 0||i.body.contentId!==void 0)&&U(`ATTACHMENT_INVALID`,`The attachment is invalid.`,`${a}.disposition and contentId are email-only`);let o=_e(i.body.contentType);o||U(`ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED`,`The attachment content type is not allowed for WhatsApp.`,`${a}.contentType ${B(i.body.contentType)} is not allowed`);let c=_[o];i.size!==null&&i.size>c&&U(`ATTACHMENT_TOO_LARGE`,`WhatsApp ${o} attachments must be at most ${c} bytes.`),n!==void 0&&o===`audio`&&U(`WHATSAPP_CAPTION_INVALID`,`WhatsApp audio does not accept a caption.`,`content must be empty for audio attachments`),n!==void 0&&n.length>1024&&U(`WHATSAPP_CAPTION_INVALID`,`A WhatsApp caption must be at most ${s} characters long.`,`content must be at most ${s} characters long`)}async function Te(e,t,n=``){try{let n=I(e.to);n!==`email`&&n!==`whatsapp`&&U(`ATTACHMENTS_NOT_SUPPORTED_FOR_CHANNEL`,`Attachments are not supported for the ${n} channel.`),e.providerTemplate!==void 0&&U(`ATTACHMENTS_PROVIDER_TEMPLATE_CONFLICT`,`Attachments cannot be combined with providerTemplate.`),Array.isArray(t)||U(`ATTACHMENT_INVALID`,`The attachment is invalid.`,`attachments must be an array`);let r=[];for(let[e,n]of t.entries())r.push(await Ce(n,`attachments.${e}`));return we(n,r,e.content),k(r.map(({body:e})=>e))}catch(e){if(!(e instanceof H))throw e;return A(new y({code:e.code,message:e.message,status:400,errors:[`${n}${e.detail}`]}))}}function Ee(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}async function W(e,t=``){let{to:n,sendAt:r,attachments:i,...a}=e,{idempotencyKey:o,...s}=a,c=L(n),l;if(i!==void 0&&i.length>0){let e=await Te({to:c,content:s.content,providerTemplate:s.providerTemplate},i,t);if(e.error)return A(e.error);l=e.data}return k(Ee({...s,to:c,sendAt:P(r),attachments:l}))}var G=class{http;constructor(e){this.http=e}async send(e,t){let n=await W(e);return n.error?A(n.error):this.http.request({method:`POST`,path:`/messages`,body:n.data,...e.idempotencyKey===void 0?{}:{idempotencyKey:e.idempotencyKey},...t?{options:t}:{}})}async batch(e,t){let{idempotencyKey:n,...r}=t??{},i=[];for(let[t,n]of e.entries()){let e=await W(n,`${t}.`);if(e.error)return A(e.error);i.push(e.data)}return this.http.request({method:`POST`,path:`/messages/batch`,body:i,...n===void 0?{}:{idempotencyKey:n},...t?{options:r}:{}})}async create(e,t){return this.send(e,t)}async retry(e,t,n){return this.http.request({method:`POST`,path:`/messages/${encodeURIComponent(e)}/retry`,idempotencyKey:t.idempotencyKey,...n?{options:n}:{}})}async get(e,t){return this.http.request({method:`GET`,path:`/messages/${encodeURIComponent(e)}`,...t?{options:t}:{}})}async retrieve(e,t){return this.get(e,t)}async list(e={},t){let{data:n,error:r}=await this.http.request({method:`GET`,path:`/messages`,query:de(e),...t?{options:t}:{}});return r?{data:null,error:r}:{data:new N(n,n=>this.list({...e,cursor:n},t)),error:null}}},K=class{messages;constructor(e){this.messages=e}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:typeof n==`string`?{sms:n}:n},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:typeof e==`string`?{sms:e}:e})),t)}},q=class{http;constructor(e){this.http=e}create(e,t){return this.http.request({method:`POST`,path:`/suppressions`,body:e,...t?{options:t}:{}})}batch(e,t){return this.http.request({method:`POST`,path:`/suppressions/batch`,body:e,...t?{options:t}:{}})}get(e,t){return this.http.request({method:`GET`,path:`/suppressions/${encodeURIComponent(e)}`,...t?{options:t}:{}})}list(e={},t){return this.http.request({method:`GET`,path:`/suppressions`,query:{email:e.email,reason:e.reason,limit:e.limit,cursor:e.cursor},...t?{options:t}:{}})}delete(e,t){return this.http.request({method:`DELETE`,path:`/suppressions/${encodeURIComponent(e)}`,...t?{options:t}:{}})}batchDelete(e,t){return this.http.request({method:`POST`,path:`/suppressions/batch/delete`,body:e,...t?{options:t}:{}})}},J=class{messages;http;constructor(e,t){this.messages=e,this.http=t}async createSubscriptionToken(e,t){return this.http.request({method:`POST`,path:`/webpush/subscription-tokens`,body:e,...t?{options:t}:{}})}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:{webpush:typeof n==`string`?{recipientId:n}:n}},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:{webpush:typeof e==`string`?{recipientId:e}:e}})),t)}},Y=class{messages;constructor(e){this.messages=e}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:typeof n==`string`?{whatsapp:n}:n},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:typeof e==`string`?{whatsapp:e}:e})),t)}},X=class{http;constructor(e){this.http=e}list(e={},t){return this.http.request({method:`GET`,path:`/whatsapp-templates`,query:{senderId:e.senderId},...t?{options:t}:{}})}get(e,t){return this.http.request({method:`GET`,path:`/whatsapp-templates/${encodeURIComponent(e)}`,...t?{options:t}:{}})}create(e,t){return this.http.request({method:`POST`,path:`/whatsapp-templates`,body:e,...t?{options:t}:{}})}update(e,t,n){return this.http.request({method:`PATCH`,path:`/whatsapp-templates/${encodeURIComponent(e)}`,body:t,...n?{options:n}:{}})}submit(e,t,n){return this.http.request({method:`POST`,path:`/whatsapp-templates/${encodeURIComponent(e)}/submit`,body:t,...n?{options:n}:{}})}sync(e,t){return this.http.request({method:`POST`,path:`/whatsapp-templates/sync`,body:e,...t?{options:t}:{}})}};function De(e){return(globalThis.process?.env?.[e])?.trim()||void 0}const Oe=`https://api.messaging.rockfeller.com.br`;var Z=class{messages;emails;whatsapp;whatsappTemplates;sms;webPush;suppressions;constructor(e){let t=typeof e==`string`?{secret:e}:e,n=t.secret?.trim();if(!n)throw Error("Messaging: `secret` é obrigatório. Use a API key do projeto, por exemplo new Messaging({ secret: process.env.MESSAGING_API_KEY }).");let r=new ue({secret:n,baseUrl:(t.baseUrl??De(`MESSAGING_BASE_URL`)??`https://api.messaging.rockfeller.com.br`).replace(/\/+$/,``),timeout:t.timeout??3e4,maxRetries:t.maxRetries??2,headers:t.headers??{},fetch:t.fetch??((e,t)=>globalThis.fetch(e,t))});this.messages=new G(r),this.emails=new M(this.messages),this.whatsapp=new Y(this.messages),this.whatsappTemplates=new X(r),this.sms=new K(this.messages),this.webPush=new J(this.messages,r),this.suppressions=new q(r)}};const ke=25,Ae=100,je=100,Me=262144,Ne=1600,Pe=65536,Fe=100,Ie=50,Le=100,Re=500,ze=998,Be=[`email`,`whatsapp`,`sms`,`webpush`],Ve=[`resend`,`unosend`,`twilio`,`meta`,`evolution`],He=[`normal`,`low`],Q=[`accepted`,`canceled`,`processing`,`sent`,`delivered`,`complained`,`bounced`,`suppressed`,`failed`],Ue=[`pending`,`canceled`,`processing`,`sent`,`delivered`,`complained`,`bounced`,`suppressed`,`failed`],We=[`delivered`,`complained`],Ge=[`bounced`,`suppressed`,`failed`],$=[`canceled`,`delivered`,`complained`,`bounced`,`suppressed`,`failed`];function Ke(e){return $.includes(e)}const qe=[`sent`,`failed`,`unknown`],Je=[`email.sent`,`email.delivered`,`email.delivery_delayed`,`email.opened`,`email.clicked`,`email.bounced`,`email.complained`,`email.failed`,`email.suppressed`,`whatsapp.sent`,`whatsapp.delivered`,`whatsapp.read`,`whatsapp.failed`,`sms.sent`,`sms.delivered`,`sms.failed`,`sms.bounced`,`webpush.sent`,`webpush.failed`,`webpush.expired`],Ye=[`manual`,`bounce`,`complaint`,`provider_suppressed`],Xe=[`api`,`dashboard`,`automatic`],Ze=`RECIPIENT_SUPPRESSED`,Qe=[`MARKETING`,`UTILITY`,`AUTHENTICATION`],$e=[`DRAFT`,`SUBMITTING`,`SUBMISSION_UNKNOWN`,`PENDING`,`APPROVED`,`REJECTED`,`PAUSED`,`DISABLED`,`DELETED`];export{l as ATTACHMENT_FILENAME_MAX_LENGTH,c as ATTACHMENT_URL_MAX_LENGTH,b as AuthenticationError,m as BLOCKED_ATTACHMENT_EXTENSIONS,T as ConnectionError,Oe as DEFAULT_BASE_URL,le as DEFAULT_MAX_RETRIES,ce as DEFAULT_TIMEOUT_MS,n as EMAIL_ATTACHMENTS_MAX_COUNT,r as EMAIL_ATTACHMENTS_MAX_TOTAL_BYTES,p as EMAIL_ATTACHMENT_CONTENT_TYPES,d as EMAIL_ATTACHMENT_DISPOSITIONS,M as Emails,u as MESSAGE_ATTACHMENT_SOURCES,qe as MESSAGE_ATTEMPT_OUTCOMES,je as MESSAGE_BATCH_MAX_SIZE,Me as MESSAGE_BODY_MAX_BYTES,We as MESSAGE_DELIVERED_STATUSES,Ue as MESSAGE_DELIVERY_STATUSES,$ as MESSAGE_DELIVERY_TERMINAL_STATUSES,Je as MESSAGE_EVENT_TYPES,Pe as MESSAGE_JSON_MAX_BYTES,ke as MESSAGE_LIST_DEFAULT_LIMIT,Ae as MESSAGE_LIST_MAX_LIMIT,He as MESSAGE_PRIORITIES,Q as MESSAGE_STATUSES,ze as MESSAGE_SUBJECT_MAX_LENGTH,Ge as MESSAGE_UNDELIVERED_STATUSES,ee as MESSAGING_ERROR_CODES,G as Messages,N as MessagesPage,Z as Messaging,Z as default,v as MessagingError,S as NotFoundError,Be as PROVIDER_CHANNELS,Ve as PROVIDER_IDS,x as PermissionError,Ze as RECIPIENT_SUPPRESSED_FAILURE_CODE,C as RateLimitError,Ne as SMS_CONTENT_MAX_LENGTH,Fe as SUPPRESSION_BATCH_MAX_SIZE,Ie as SUPPRESSION_LIST_DEFAULT_LIMIT,Le as SUPPRESSION_LIST_MAX_LIMIT,Re as SUPPRESSION_NOTE_MAX_LENGTH,Ye as SUPPRESSION_REASONS,Xe as SUPPRESSION_SOURCES,w as ServerError,K as Sms,q as Suppressions,E as TimeoutError,j as VERSION,y as ValidationError,i as WHATSAPP_ATTACHMENTS_MAX_COUNT,s as WHATSAPP_CAPTION_MAX_LENGTH,a as WHATSAPP_IMAGE_MAX_BYTES,h as WHATSAPP_MEDIA_KINDS,o as WHATSAPP_MEDIA_MAX_BYTES,_ as WHATSAPP_MEDIA_MAX_BYTES_BY_KIND,g as WHATSAPP_MEDIA_TYPES,Qe as WHATSAPP_TEMPLATE_CATEGORIES,$e as WHATSAPP_TEMPLATE_STATUSES,J as WebPush,Y as WhatsApp,X as WhatsAppTemplates,A as failure,te as isMessagingError,Ke as isTerminalDeliveryStatus,k as success};
|
|
1
|
+
import{t as e}from"../version-8Zc_uUvG.js";const t=1048576,n=10,r=20*t,i=1,a=5*t,o=10*t,s=1024,c=2048,l=255,u=[`upload`,`url`],d=[`attachment`,`inline`],f=[`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/vnd.ms-powerpoint`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`],p=[`application/pdf`,`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`text/csv`,`text/plain`,...f,`application/vnd.oasis.opendocument.text`,`application/vnd.oasis.opendocument.spreadsheet`,`application/zip`,`text/calendar`],m=/* @__PURE__ */ `apk.app.bat.cmd.com.cpl.dll.dmg.exe.hta.jar.js.jse.lnk.msi.msp.pif.ps1.reg.scr.sh.vb.vbe.vbs.wsf.wsh`.split(`.`),h=[`image`,`video`,`audio`,`document`],g={image:[`image/jpeg`,`image/png`],video:[`video/mp4`,`video/3gpp`],audio:[`audio/aac`,`audio/mp4`,`audio/mpeg`,`audio/amr`,`audio/ogg`],document:[`application/pdf`,...f,`text/plain`,`text/csv`,`application/zip`]},_={image:a,video:o,audio:o,document:o},ee=/* @__PURE__ */ `UNAUTHENTICATED.INVALID_API_KEY.ACTIVE_PROJECT_REQUIRED.PROJECT_ROLE_REQUIRED.VALIDATION_ERROR.FROM_DOMAIN_NOT_VERIFIED.SENDER_NOT_FOUND.WHATSAPP_TEMPLATE_NOT_FOUND.WHATSAPP_TEMPLATE_CONFLICT.WHATSAPP_TEMPLATE_PROVIDER_UNSUPPORTED.WHATSAPP_TEMPLATE_SUBMISSION_FAILED.WHATSAPP_TEMPLATE_SYNC_FAILED.WHATSAPP_TEMPLATE_INVALID_STATE.WHATSAPP_TEMPLATE_BODY_CONFLICT.ATTACHMENTS_NOT_SUPPORTED_FOR_CHANNEL.ATTACHMENTS_PROVIDER_TEMPLATE_CONFLICT.ATTACHMENT_INVALID.ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED.ATTACHMENT_TOO_LARGE.ATTACHMENTS_LIMIT_EXCEEDED.ATTACHMENT_URL_NOT_ALLOWED.WHATSAPP_CAPTION_INVALID.PAYLOAD_TOO_LARGE.ATTACHMENT_STORAGE_UNAVAILABLE.ATTACHMENT_STORAGE_NOT_CONFIGURED.ATTACHMENT_EXPIRED.MESSAGE_NOT_FOUND.SUPPRESSION_NOT_FOUND.MESSAGE_NOT_RETRYABLE.MESSAGE_CONTENT_EXPIRED.IDEMPOTENCY_KEY_REUSED.ROUTE_NOT_FOUND.INTERNAL_SERVER_ERROR.RATE_LIMIT_EXCEEDED.CONNECTION_ERROR.TIMEOUT.UNEXPECTED_RESPONSE`.split(`.`);var v=class extends Error{name=`MessagingError`;code;status;errors;constructor(e){super(e.message,{cause:e.cause}),this.code=e.code,this.status=e.status,this.errors=e.errors}get retryable(){return this.status===0||this.status===408||this.status===429||this.status>=500}toJSON(){return{name:this.name,code:this.code,message:this.message,status:this.status,...this.errors?{errors:this.errors}:{}}}},y=class extends v{name=`ValidationError`},b=class extends v{name=`AuthenticationError`},x=class extends v{name=`PermissionError`},S=class extends v{name=`NotFoundError`},C=class extends v{name=`RateLimitError`;retryAfter;constructor(e){super(e),this.retryAfter=e.retryAfter}},w=class extends v{name=`ServerError`},T=class extends v{name=`ConnectionError`},E=class extends v{name=`TimeoutError`};function te(e){return e instanceof v}function ne(e){let t={code:e.code,message:e.message,status:e.status,...e.errors?{errors:e.errors}:{}};return e.status===429?new C({...t,...e.retryAfter===void 0?{}:{retryAfter:e.retryAfter}}):e.status>=500?new w(t):e.status===401?new b(t):e.status===403?new x(t):e.status===404?new S(t):e.status===400||e.status===422?new y(t):new v(t)}function re(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!==void 0){if(Array.isArray(r))for(let e of r)t.append(n,String(e));else t.append(n,r instanceof Date?r.toISOString():String(r))}let n=t.toString();return n?`?${n}`:``}const D=8e3,ie=e=>new Promise(t=>setTimeout(t,e));function ae(e,t){if(t!==void 0)return Math.min(t*1e3,D);let n=Math.min(500*2**e,D);return Math.round(n*(.5+Math.random()*.5))}function oe(e){if(!e)return;let t=Number(e);if(Number.isFinite(t)&&t>=0)return t;let n=Date.parse(e);if(!Number.isNaN(n))return Math.max(0,Math.round((n-Date.now())/1e3))}function O(e){if(e.length===1)return e[0];let t=AbortSignal.any;if(t)return t(e);let n=new AbortController;for(let t of e){if(t.aborted){n.abort(t.reason);break}t.addEventListener(`abort`,()=>n.abort(t.reason),{once:!0})}return n.signal}function k(e){return{data:e,error:null}}function A(e){return{data:null,error:e}}const j=e,se=`rockdev-messaging-node/${j}`,ce=3e4,le=2;var ue=class{config;constructor(e){this.config=e}async request(e){let t=`${this.config.baseUrl}/v1${e.path}${e.query?re(e.query):``}`,n=e.method===`GET`||e.idempotencyKey!==void 0?this.config.maxRetries:0,r;for(let i=0;i<=n;i+=1){let a=await this.attempt(t,e);if(a.error===null)return a;if(r=a.error,!a.error.retryable||e.options?.signal?.aborted||i===n)break;await ie(ae(i,a.error.retryAfter))}return A(r)}async attempt(e,t){let n=t.options?.timeout??this.config.timeout,r=new AbortController,i=setTimeout(()=>r.abort(),n),a=[r.signal];t.options?.signal&&a.push(t.options.signal);let o;try{o=await this.config.fetch(e,{method:t.method,headers:this.headers(t),signal:O(a),...t.body===void 0?{}:{body:JSON.stringify(t.body)}})}catch(e){return t.options?.signal?.aborted?A(new v({code:`CONNECTION_ERROR`,message:`The request was aborted by the caller.`,status:0,cause:e})):r.signal.aborted?A(new E({code:`TIMEOUT`,message:`The request did not complete within ${n}ms.`,status:0,cause:e})):A(new T({code:`CONNECTION_ERROR`,message:e instanceof Error?e.message:`The request could not reach the Messaging API.`,status:0,cause:e}))}finally{clearTimeout(i)}return this.parse(o)}headers(e){let t=e=>Object.fromEntries(Object.entries(e).filter(([e])=>e.toLowerCase()!==`idempotency-key`));return{accept:`application/json`,authorization:`Bearer ${this.config.secret}`,"user-agent":se,...e.body===void 0?{}:{"content-type":`application/json`},...t(this.config.headers),...t(e.options?.headers??{}),...e.idempotencyKey===void 0?{}:{"idempotency-key":e.idempotencyKey}}}async parse(e){let t=await e.text().catch(()=>``),n;try{n=t?JSON.parse(t):void 0}catch{n=void 0}if(!e.ok){let t=oe(e.headers.get(`retry-after`));return A(ne({code:n?.code??`INTERNAL_SERVER_ERROR`,message:n?.message??`The Messaging API responded with ${e.status}.`,status:e.status,...n?.errors?{errors:n.errors}:{},...t===void 0?{}:{retryAfter:t}}))}return!n||n.data===void 0?A(new v({code:`UNEXPECTED_RESPONSE`,message:`The Messaging API responded without the expected body.`,status:e.status})):k(n.data)}},M=class{messages;constructor(e){this.messages=e}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:typeof n==`string`?{email:n}:n},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:typeof e==`string`?{email:e}:e})),t)}},N=class e{fetchPage;messages;nextCursor;constructor(e,t){this.fetchPage=t,this.messages=e.messages,this.nextCursor=e.nextCursor}get hasMore(){return this.nextCursor!==null}async next(){return this.nextCursor===null?{data:new e({messages:[],nextCursor:null},this.fetchPage),error:null}:this.fetchPage(this.nextCursor)}async*[Symbol.asyncIterator](){let e=this;for(;;){for(let t of e.messages)yield t;if(!e.hasMore)return;let{data:t,error:n}=await e.next();if(n)throw n;e=t}}};function P(e){if(e!==void 0)return e instanceof Date?e.toISOString():e}function de(e){return{status:e.status,channel:e.channel,to:e.to,search:e.search,scheduled:e.scheduled,createdAfter:P(e.createdAfter),createdBefore:P(e.createdBefore),limit:e.limit,cursor:e.cursor}}const F=24576;function fe(e){if(typeof e.toBase64==`function`)return e.toBase64();let t=globalThis.Buffer;if(t)return t.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`);let n=``;for(let t=0;t<e.length;t+=F){let r=e.subarray(t,t+F),i=``;for(let e=0;e<r.length;e+=1)i+=String.fromCharCode(r[e]);n+=btoa(i)}return n}function pe(e){let t=e.endsWith(`==`)?2:+!!e.endsWith(`=`);return e.length/4*3-t}function me(e){return typeof Blob<`u`&&e instanceof Blob}function I(e){return`email`in e&&e.email!==void 0?`email`:`whatsapp`in e&&e.whatsapp!==void 0?`whatsapp`:`sms`in e&&e.sms!==void 0?`sms`:`webpush`}function L(e){return typeof e==`string`?e.includes(`@`)?{email:e}:{whatsapp:e}:e}function R(e){let t=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(e);if(!t)return null;let[n,r]=[Number(t[1]),Number(t[2])];return n===0||n===10||n===127||n===100&&r>=64&&r<=127||n===169&&r===254||n===172&&r>=16&&r<=31||n===192&&r===168||n===198&&(r===18||r===19)||n>=224}function z(e){if(!e.startsWith(`[`))return null;let t=e.slice(1,-1).toLowerCase(),n=/^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(t);return n?.[1]?R(n[1])??!0:t===`::`||t===`::1`||t.startsWith(`::ffff:`)||/^f[cd]/.test(t)||/^fe[89ab]/.test(t)||t.startsWith(`ff`)}function he(e){try{return new URL(e)}catch{return null}}const ge={pdf:`application/pdf`,png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,gif:`image/gif`,webp:`image/webp`,csv:`text/csv`,txt:`text/plain`,doc:`application/msword`,docx:`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,xls:`application/vnd.ms-excel`,xlsx:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,ppt:`application/vnd.ms-powerpoint`,pptx:`application/vnd.openxmlformats-officedocument.presentationml.presentation`,odt:`application/vnd.oasis.opendocument.text`,ods:`application/vnd.oasis.opendocument.spreadsheet`,zip:`application/zip`,ics:`text/calendar`,mp4:`video/mp4`,"3gp":`video/3gpp`,aac:`audio/aac`,m4a:`audio/mp4`,mp3:`audio/mpeg`,amr:`audio/amr`,ogg:`audio/ogg`,opus:`audio/ogg`};function B(e){return(e.split(`;`)[0]??``).trim().toLowerCase()}function V(e){let t=e.lastIndexOf(`.`);return t<=0||t===e.length-1?``:e.slice(t+1).toLowerCase()}function _e(e){let t=B(e);for(let e of h)if(g[e].includes(t))return e;return null}function ve(e){return ge[V(e.trim())]}const ye=/^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*(\s*;.*)?$/i,be=/^[A-Za-z0-9+/]*={0,2}$/,xe=/[/\\\u0000-\u001f\u007f]/;var H=class{code;message;detail;constructor(e,t,n){this.code=e,this.message=t,this.detail=n}};function U(e,t,n=t){throw new H(e,t,n)}function Se(e,t){let n=e=>U(`ATTACHMENT_URL_NOT_ALLOWED`,`The attachment URL is not allowed: ${e}.`,`${t}.url ${e}`);e.length>2048&&n(`must be at most ${c} characters long`);let r=he(e)??n(`must be a valid URL`);r.protocol!==`https:`&&n(`must use https`),(r.username||r.password)&&n(`must not contain credentials`),r.port&&r.port!==`443`&&n(`must use the default port`);let i=r.hostname.toLowerCase().replace(/\.$/,``);(i===`localhost`||i.endsWith(`.localhost`)||i.endsWith(`.local`)||i.endsWith(`.internal`))&&n(`must not point to a local host`),!i.startsWith(`[`)&&!i.includes(`.`)&&n(`must use a fully qualified host name`),(R(i)||z(i))&&n(`must not point to a private address`)}async function Ce(e,t){let n=e=>U(`ATTACHMENT_INVALID`,`The attachment is invalid.`,e);typeof e==`object`&&e||n(`${t} must be an object`);let{filename:r,disposition:i,contentId:a}=e;(typeof r!=`string`||r.trim()===``)&&n(`${t}.filename is required`),r.length>255&&n(`${t}.filename must be at most 255 characters long`),xe.test(r)&&n(`${t}.filename must not contain path separators or control characters`);let o=`url`in e&&e.url!==void 0;o===(`content`in e&&e.content!==void 0)&&n(`${t} must have exactly one of url or content`),i!==void 0&&!d.includes(i)&&n(`${t}.disposition must be one of attachment, inline`),a!==void 0&&(typeof a!=`string`||a===``||a.length>255)&&n(`${t}.contentId must be a non-empty string of at most 255 characters`),i===`inline`&&(a??``).trim()===``&&n(`${t}.contentId is required for inline attachments`);let s={...i===void 0?{}:{disposition:i},...a===void 0?{}:{contentId:a}},c=e=>e===void 0||e.trim()===``?n(`${t}.contentType is required`):(ye.test(e)||n(`${t}.contentType must be a type/subtype MIME type`),e);if(o){let{url:i}=e;return typeof i==`string`?(Se(i,t),{body:{filename:r,contentType:c(e.contentType),url:i,...s},size:null}):n(`${t}.url must be a string`)}let{content:l}=e,u,f,p;if(typeof l==`string`)l.length%4==0&&be.test(l)||n(`${t}.content must be valid base64`),u=l,f=pe(l);else{let e;if(l instanceof Uint8Array)e=l;else if(l instanceof ArrayBuffer)e=new Uint8Array(l);else if(ArrayBuffer.isView(l))e=new Uint8Array(l.buffer,l.byteOffset,l.byteLength);else if(me(l))p=l.type||void 0,e=new Uint8Array(await l.arrayBuffer());else return n(`${t}.content must be a Uint8Array, ArrayBuffer, Blob or base64 string`);u=fe(e),f=e.byteLength}return{body:{filename:r,contentType:c(e.contentType??p??ve(r)),content:u,...s},size:f}}function we(e,t,n){if(e===`email`){t.length>10&&U(`ATTACHMENTS_LIMIT_EXCEEDED`,`An email accepts at most 10 attachments.`);let e=0;t.forEach(({body:t,size:n},r)=>{let i=`attachments.${r}`;p.includes(B(t.contentType))||U(`ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED`,`The attachment content type is not allowed for email.`,`${i}.contentType ${B(t.contentType)} is not allowed`),m.includes(V(t.filename.trim()))&&U(`ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED`,`The attachment file extension is not allowed.`,`${i}.filename has a blocked extension`),e+=n??0}),e>20971520&&U(`ATTACHMENT_TOO_LARGE`,`Email attachments must add up to at most ${r} bytes.`);return}t.length>1&&U(`ATTACHMENTS_LIMIT_EXCEEDED`,`A WhatsApp message accepts at most 1 attachment.`);let[i]=t;if(!i)return;let a=`attachments.0`;(i.body.disposition!==void 0||i.body.contentId!==void 0)&&U(`ATTACHMENT_INVALID`,`The attachment is invalid.`,`${a}.disposition and contentId are email-only`);let o=_e(i.body.contentType);o||U(`ATTACHMENT_CONTENT_TYPE_NOT_ALLOWED`,`The attachment content type is not allowed for WhatsApp.`,`${a}.contentType ${B(i.body.contentType)} is not allowed`);let c=_[o];i.size!==null&&i.size>c&&U(`ATTACHMENT_TOO_LARGE`,`WhatsApp ${o} attachments must be at most ${c} bytes.`),n!==void 0&&o===`audio`&&U(`WHATSAPP_CAPTION_INVALID`,`WhatsApp audio does not accept a caption.`,`content must be empty for audio attachments`),n!==void 0&&n.length>1024&&U(`WHATSAPP_CAPTION_INVALID`,`A WhatsApp caption must be at most ${s} characters long.`,`content must be at most ${s} characters long`)}async function Te(e,t,n=``){try{let n=I(e.to);n!==`email`&&n!==`whatsapp`&&U(`ATTACHMENTS_NOT_SUPPORTED_FOR_CHANNEL`,`Attachments are not supported for the ${n} channel.`),e.providerTemplate!==void 0&&U(`ATTACHMENTS_PROVIDER_TEMPLATE_CONFLICT`,`Attachments cannot be combined with providerTemplate.`),Array.isArray(t)||U(`ATTACHMENT_INVALID`,`The attachment is invalid.`,`attachments must be an array`);let r=[];for(let[e,n]of t.entries())r.push(await Ce(n,`attachments.${e}`));return we(n,r,e.content),k(r.map(({body:e})=>e))}catch(e){if(!(e instanceof H))throw e;return A(new y({code:e.code,message:e.message,status:400,errors:[`${n}${e.detail}`]}))}}function Ee(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}async function W(e,t=``){let{to:n,sendAt:r,attachments:i,...a}=e,{idempotencyKey:o,...s}=a,c=L(n),l;if(i!==void 0&&i.length>0){let e=await Te({to:c,content:s.content,providerTemplate:s.providerTemplate},i,t);if(e.error)return A(e.error);l=e.data}return k(Ee({...s,to:c,sendAt:P(r),attachments:l}))}var G=class{http;constructor(e){this.http=e}async send(e,t){let n=await W(e);return n.error?A(n.error):this.http.request({method:`POST`,path:`/messages`,body:n.data,...e.idempotencyKey===void 0?{}:{idempotencyKey:e.idempotencyKey},...t?{options:t}:{}})}async batch(e,t){let{idempotencyKey:n,...r}=t??{},i=[];for(let[t,n]of e.entries()){let e=await W(n,`${t}.`);if(e.error)return A(e.error);i.push(e.data)}return this.http.request({method:`POST`,path:`/messages/batch`,body:i,...n===void 0?{}:{idempotencyKey:n},...t?{options:r}:{}})}async create(e,t){return this.send(e,t)}async retry(e,t,n){return this.http.request({method:`POST`,path:`/messages/${encodeURIComponent(e)}/retry`,idempotencyKey:t.idempotencyKey,...n?{options:n}:{}})}async get(e,t){return this.http.request({method:`GET`,path:`/messages/${encodeURIComponent(e)}`,...t?{options:t}:{}})}async retrieve(e,t){return this.get(e,t)}async list(e={},t){let{data:n,error:r}=await this.http.request({method:`GET`,path:`/messages`,query:de(e),...t?{options:t}:{}});return r?{data:null,error:r}:{data:new N(n,n=>this.list({...e,cursor:n},t)),error:null}}},K=class{messages;constructor(e){this.messages=e}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:typeof n==`string`?{sms:n}:n},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:typeof e==`string`?{sms:e}:e})),t)}},q=class{http;constructor(e){this.http=e}create(e,t){return this.http.request({method:`POST`,path:`/suppressions`,body:e,...t?{options:t}:{}})}batch(e,t){return this.http.request({method:`POST`,path:`/suppressions/batch`,body:e,...t?{options:t}:{}})}get(e,t){return this.http.request({method:`GET`,path:`/suppressions/${encodeURIComponent(e)}`,...t?{options:t}:{}})}list(e={},t){return this.http.request({method:`GET`,path:`/suppressions`,query:{email:e.email,reason:e.reason,limit:e.limit,cursor:e.cursor},...t?{options:t}:{}})}delete(e,t){return this.http.request({method:`DELETE`,path:`/suppressions/${encodeURIComponent(e)}`,...t?{options:t}:{}})}batchDelete(e,t){return this.http.request({method:`POST`,path:`/suppressions/batch/delete`,body:e,...t?{options:t}:{}})}},J=class{messages;http;constructor(e,t){this.messages=e,this.http=t}async createSubscriptionToken(e,t){return this.http.request({method:`POST`,path:`/webpush/subscription-tokens`,body:e,...t?{options:t}:{}})}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:{webpush:typeof n==`string`?{recipientId:n}:n}},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:{webpush:typeof e==`string`?{recipientId:e}:e}})),t)}},Y=class{messages;constructor(e){this.messages=e}async send(e,t){let{to:n,...r}=e;return this.messages.send({...r,to:typeof n==`string`?{whatsapp:n}:n},t)}async batch(e,t){return this.messages.batch(e.map(({to:e,...t})=>({...t,to:typeof e==`string`?{whatsapp:e}:e})),t)}},X=class{http;constructor(e){this.http=e}list(e={},t){return this.http.request({method:`GET`,path:`/whatsapp-templates`,query:{senderId:e.senderId},...t?{options:t}:{}})}get(e,t){return this.http.request({method:`GET`,path:`/whatsapp-templates/${encodeURIComponent(e)}`,...t?{options:t}:{}})}create(e,t){return this.http.request({method:`POST`,path:`/whatsapp-templates`,body:e,...t?{options:t}:{}})}update(e,t,n){return this.http.request({method:`PATCH`,path:`/whatsapp-templates/${encodeURIComponent(e)}`,body:t,...n?{options:n}:{}})}submit(e,t,n){return this.http.request({method:`POST`,path:`/whatsapp-templates/${encodeURIComponent(e)}/submit`,body:t,...n?{options:n}:{}})}sync(e,t){return this.http.request({method:`POST`,path:`/whatsapp-templates/sync`,body:e,...t?{options:t}:{}})}};function De(e){return(globalThis.process?.env?.[e])?.trim()||void 0}const Oe=`https://api.messaging.rockfeller.com.br`;var Z=class{messages;emails;whatsapp;whatsappTemplates;sms;webPush;suppressions;constructor(e){let t=typeof e==`string`?{secret:e}:e,n=t.secret?.trim();if(!n)throw Error("Messaging: `secret` é obrigatório. Use a API key do projeto, por exemplo new Messaging({ secret: process.env.MESSAGING_API_KEY }).");let r=new ue({secret:n,baseUrl:(t.baseUrl??De(`MESSAGING_BASE_URL`)??`https://api.messaging.rockfeller.com.br`).replace(/\/+$/,``),timeout:t.timeout??3e4,maxRetries:t.maxRetries??2,headers:t.headers??{},fetch:t.fetch??((e,t)=>globalThis.fetch(e,t))});this.messages=new G(r),this.emails=new M(this.messages),this.whatsapp=new Y(this.messages),this.whatsappTemplates=new X(r),this.sms=new K(this.messages),this.webPush=new J(this.messages,r),this.suppressions=new q(r)}};const ke=25,Ae=100,je=100,Me=262144,Ne=1600,Pe=65536,Fe=100,Ie=50,Le=100,Re=500,ze=998,Be=[`email`,`whatsapp`,`sms`,`webpush`],Ve=[`resend`,`unosend`,`twilio`,`meta`,`evolution`],He=[`normal`,`low`],Q=[`accepted`,`canceled`,`processing`,`sent`,`delivered`,`complained`,`bounced`,`suppressed`,`failed`],Ue=[`pending`,`canceled`,`processing`,`sent`,`delivered`,`complained`,`bounced`,`suppressed`,`failed`],We=[`delivered`,`complained`],Ge=[`bounced`,`suppressed`,`failed`],$=[`canceled`,`delivered`,`complained`,`bounced`,`suppressed`,`failed`];function Ke(e){return $.includes(e)}const qe=[`sent`,`failed`,`unknown`],Je=[`email.sent`,`email.delivered`,`email.delivery_delayed`,`email.opened`,`email.clicked`,`email.bounced`,`email.complained`,`email.failed`,`email.suppressed`,`whatsapp.sent`,`whatsapp.delivered`,`whatsapp.read`,`whatsapp.failed`,`sms.sent`,`sms.delivered`,`sms.failed`,`sms.bounced`,`webpush.sent`,`webpush.failed`,`webpush.expired`],Ye=[`manual`,`bounce`,`complaint`,`provider_suppressed`],Xe=[`api`,`dashboard`,`automatic`],Ze=`RECIPIENT_SUPPRESSED`,Qe=[`MARKETING`,`UTILITY`,`AUTHENTICATION`],$e=[`DRAFT`,`SUBMITTING`,`SUBMISSION_UNKNOWN`,`PENDING`,`APPROVED`,`REJECTED`,`PAUSED`,`DISABLED`,`DELETED`];export{l as ATTACHMENT_FILENAME_MAX_LENGTH,c as ATTACHMENT_URL_MAX_LENGTH,b as AuthenticationError,m as BLOCKED_ATTACHMENT_EXTENSIONS,T as ConnectionError,Oe as DEFAULT_BASE_URL,le as DEFAULT_MAX_RETRIES,ce as DEFAULT_TIMEOUT_MS,n as EMAIL_ATTACHMENTS_MAX_COUNT,r as EMAIL_ATTACHMENTS_MAX_TOTAL_BYTES,p as EMAIL_ATTACHMENT_CONTENT_TYPES,d as EMAIL_ATTACHMENT_DISPOSITIONS,M as Emails,u as MESSAGE_ATTACHMENT_SOURCES,qe as MESSAGE_ATTEMPT_OUTCOMES,je as MESSAGE_BATCH_MAX_SIZE,Me as MESSAGE_BODY_MAX_BYTES,We as MESSAGE_DELIVERED_STATUSES,Ue as MESSAGE_DELIVERY_STATUSES,$ as MESSAGE_DELIVERY_TERMINAL_STATUSES,Je as MESSAGE_EVENT_TYPES,Pe as MESSAGE_JSON_MAX_BYTES,ke as MESSAGE_LIST_DEFAULT_LIMIT,Ae as MESSAGE_LIST_MAX_LIMIT,He as MESSAGE_PRIORITIES,Q as MESSAGE_STATUSES,ze as MESSAGE_SUBJECT_MAX_LENGTH,Ge as MESSAGE_UNDELIVERED_STATUSES,ee as MESSAGING_ERROR_CODES,G as Messages,N as MessagesPage,Z as Messaging,Z as default,v as MessagingError,S as NotFoundError,Be as PROVIDER_CHANNELS,Ve as PROVIDER_IDS,x as PermissionError,Ze as RECIPIENT_SUPPRESSED_FAILURE_CODE,C as RateLimitError,Ne as SMS_CONTENT_MAX_LENGTH,Fe as SUPPRESSION_BATCH_MAX_SIZE,Ie as SUPPRESSION_LIST_DEFAULT_LIMIT,Le as SUPPRESSION_LIST_MAX_LIMIT,Re as SUPPRESSION_NOTE_MAX_LENGTH,Ye as SUPPRESSION_REASONS,Xe as SUPPRESSION_SOURCES,w as ServerError,K as Sms,q as Suppressions,E as TimeoutError,j as VERSION,y as ValidationError,i as WHATSAPP_ATTACHMENTS_MAX_COUNT,s as WHATSAPP_CAPTION_MAX_LENGTH,a as WHATSAPP_IMAGE_MAX_BYTES,h as WHATSAPP_MEDIA_KINDS,o as WHATSAPP_MEDIA_MAX_BYTES,_ as WHATSAPP_MEDIA_MAX_BYTES_BY_KIND,g as WHATSAPP_MEDIA_TYPES,Qe as WHATSAPP_TEMPLATE_CATEGORIES,$e as WHATSAPP_TEMPLATE_STATUSES,J as WebPush,Y as WhatsApp,X as WhatsAppTemplates,A as failure,te as isMessagingError,Ke as isTerminalDeliveryStatus,k as success};
|
package/dist/sso/client.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as SchoolList, S as School, T as SchoolPermissions, b as TeamRoleOrigin, c as AppRoleGrant, d as AppRoleMember, g as TeamMember, m as TeamInvitation, p as Page, s as AppRole, t as rockfeller, u as AppRoleList, w as SchoolMembership, x as Permission } from "../index-cKCKFKLi.cjs";
|
|
2
2
|
import { BetterAuthClientPlugin } from "better-auth/client";
|
|
3
3
|
interface SignInWithRockfellerInput {
|
|
4
4
|
/** Para onde voltar depois do login. */
|
|
@@ -90,5 +90,5 @@ export declare function rockfellerClient(): {
|
|
|
90
90
|
};
|
|
91
91
|
};
|
|
92
92
|
};
|
|
93
|
-
export type { ConnectTeamInput, Page, Permission, School, SchoolList, SchoolMembership, SchoolPermissions, SignInWithRockfellerInput, TeamInvitation, TeamMember };
|
|
93
|
+
export type { AppRole, AppRoleGrant, AppRoleList, AppRoleMember, ConnectTeamInput, Page, Permission, School, SchoolList, SchoolMembership, SchoolPermissions, SignInWithRockfellerInput, TeamInvitation, TeamMember, TeamRoleOrigin };
|
|
94
94
|
//# sourceMappingURL=client.d.cts.map
|
package/dist/sso/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as SchoolList, S as School, T as SchoolPermissions, b as TeamRoleOrigin, c as AppRoleGrant, d as AppRoleMember, g as TeamMember, m as TeamInvitation, p as Page, s as AppRole, t as rockfeller, u as AppRoleList, w as SchoolMembership, x as Permission } from "../index-cKCKFKLi.js";
|
|
2
2
|
import { BetterAuthClientPlugin } from "better-auth/client";
|
|
3
3
|
interface SignInWithRockfellerInput {
|
|
4
4
|
/** Para onde voltar depois do login. */
|
|
@@ -90,5 +90,5 @@ export declare function rockfellerClient(): {
|
|
|
90
90
|
};
|
|
91
91
|
};
|
|
92
92
|
};
|
|
93
|
-
export type { ConnectTeamInput, Page, Permission, School, SchoolList, SchoolMembership, SchoolPermissions, SignInWithRockfellerInput, TeamInvitation, TeamMember };
|
|
93
|
+
export type { AppRole, AppRoleGrant, AppRoleList, AppRoleMember, ConnectTeamInput, Page, Permission, School, SchoolList, SchoolMembership, SchoolPermissions, SignInWithRockfellerInput, TeamInvitation, TeamMember, TeamRoleOrigin };
|
|
94
94
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/sso/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_rolldown_runtime = require("../rolldown-runtime-xuxB8TGW.cjs");
|
|
3
|
-
const require_accounts = require("../accounts-
|
|
3
|
+
const require_accounts = require("../accounts-BscmRiXc.cjs");
|
|
4
4
|
const require_constants = require("../constants-rCR-LNSN.cjs");
|
|
5
5
|
let better_auth_api = require("better-auth/api");
|
|
6
6
|
let zod = require("zod");
|
|
@@ -195,6 +195,25 @@ function createHasPermissionEndpoint(runtime) {
|
|
|
195
195
|
}));
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
// src/modules/sso/plugin/endpoints/invite-app-role-member.ts
|
|
199
|
+
function createInviteAppRoleMemberEndpoint(runtime) {
|
|
200
|
+
const { accounts, teamToken } = runtime;
|
|
201
|
+
return (0, better_auth_api.createAuthEndpoint)("/rockfeller/app-roles/invite", {
|
|
202
|
+
method: "POST",
|
|
203
|
+
use: [better_auth_api.sessionMiddleware],
|
|
204
|
+
body: zod.object({
|
|
205
|
+
organization: zod.string().min(1),
|
|
206
|
+
email: zod.string().email(),
|
|
207
|
+
name: zod.string().min(1),
|
|
208
|
+
roles: zod.array(zod.string().min(1)).min(1).max(10)
|
|
209
|
+
})
|
|
210
|
+
}, handle(async (ctx) => {
|
|
211
|
+
const { organization, ...input } = ctx.body;
|
|
212
|
+
const invitation = await accounts.appRoles.invite(await teamToken(ctx), organization, input);
|
|
213
|
+
return ctx.json(invitation);
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
|
|
198
217
|
// src/modules/sso/plugin/endpoints/invite-team-member.ts
|
|
199
218
|
function createInviteTeamMemberEndpoint(runtime) {
|
|
200
219
|
const { accounts, teamToken } = runtime;
|
|
@@ -221,6 +240,39 @@ function createInviteTeamMemberEndpoint(runtime) {
|
|
|
221
240
|
}));
|
|
222
241
|
}
|
|
223
242
|
|
|
243
|
+
// src/modules/sso/plugin/endpoints/list-app-role-members.ts
|
|
244
|
+
function createListAppRoleMembersEndpoint(runtime) {
|
|
245
|
+
const { accounts, teamToken } = runtime;
|
|
246
|
+
return (0, better_auth_api.createAuthEndpoint)("/rockfeller/app-roles/members", {
|
|
247
|
+
method: "GET",
|
|
248
|
+
use: [better_auth_api.sessionMiddleware],
|
|
249
|
+
query: zod.object({
|
|
250
|
+
organization: zod.string().min(1),
|
|
251
|
+
q: zod.string().optional(),
|
|
252
|
+
role: zod.string().optional(),
|
|
253
|
+
cursor: zod.string().optional(),
|
|
254
|
+
limit: zod.coerce.number().int().min(1).max(15).optional()
|
|
255
|
+
})
|
|
256
|
+
}, handle(async (ctx) => {
|
|
257
|
+
const { organization, ...query } = ctx.query;
|
|
258
|
+
const page = await accounts.appRoles.members(await teamToken(ctx), organization, query);
|
|
259
|
+
return ctx.json(page);
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// src/modules/sso/plugin/endpoints/list-app-roles.ts
|
|
264
|
+
function createListAppRolesEndpoint(runtime) {
|
|
265
|
+
const { accounts, teamToken } = runtime;
|
|
266
|
+
return (0, better_auth_api.createAuthEndpoint)("/rockfeller/app-roles", {
|
|
267
|
+
method: "GET",
|
|
268
|
+
use: [better_auth_api.sessionMiddleware],
|
|
269
|
+
query: zod.object({ organization: zod.string().min(1) })
|
|
270
|
+
}, handle(async (ctx) => {
|
|
271
|
+
const list = await accounts.appRoles.list(await teamToken(ctx), ctx.query.organization);
|
|
272
|
+
return ctx.json(list);
|
|
273
|
+
}));
|
|
274
|
+
}
|
|
275
|
+
|
|
224
276
|
// src/modules/sso/plugin/endpoints/list-schools.ts
|
|
225
277
|
function createListSchoolsEndpoint(runtime) {
|
|
226
278
|
const { accounts } = runtime;
|
|
@@ -253,6 +305,7 @@ function createListTeamMembersEndpoint(runtime) {
|
|
|
253
305
|
"invite",
|
|
254
306
|
"franchisor",
|
|
255
307
|
"app",
|
|
308
|
+
"app_admin",
|
|
256
309
|
"sandbox"
|
|
257
310
|
]).optional(),
|
|
258
311
|
cursor: zod.string().optional(),
|
|
@@ -302,6 +355,20 @@ function createRequirePermissionEndpoint(runtime) {
|
|
|
302
355
|
}));
|
|
303
356
|
}
|
|
304
357
|
|
|
358
|
+
// src/modules/sso/plugin/endpoints/revoke-app-roles.ts
|
|
359
|
+
function createRevokeAppRolesEndpoint(runtime) {
|
|
360
|
+
const { accounts, teamToken } = runtime;
|
|
361
|
+
return (0, better_auth_api.createAuthEndpoint)("/rockfeller/app-roles/revoke", {
|
|
362
|
+
method: "POST",
|
|
363
|
+
use: [better_auth_api.sessionMiddleware],
|
|
364
|
+
body: zod.object({
|
|
365
|
+
organization: zod.string().min(1),
|
|
366
|
+
userId: zod.string().min(1),
|
|
367
|
+
roles: zod.array(zod.string().min(1)).min(1).max(10)
|
|
368
|
+
})
|
|
369
|
+
}, handle(async (ctx) => ctx.json(await accounts.appRoles.revoke(await teamToken(ctx), ctx.body.organization, ctx.body.userId, ctx.body.roles))));
|
|
370
|
+
}
|
|
371
|
+
|
|
305
372
|
// src/modules/sso/plugin/endpoints/revoke-team-roles.ts
|
|
306
373
|
function createRevokeTeamRolesEndpoint(runtime) {
|
|
307
374
|
const { accounts, teamToken } = runtime;
|
|
@@ -806,6 +873,10 @@ function rockfeller(options) {
|
|
|
806
873
|
listTeamMembers: createListTeamMembersEndpoint(runtime),
|
|
807
874
|
inviteTeamMember: createInviteTeamMemberEndpoint(runtime),
|
|
808
875
|
revokeTeamRoles: createRevokeTeamRolesEndpoint(runtime),
|
|
876
|
+
listAppRoles: createListAppRolesEndpoint(runtime),
|
|
877
|
+
listAppRoleMembers: createListAppRoleMembersEndpoint(runtime),
|
|
878
|
+
inviteAppRoleMember: createInviteAppRoleMemberEndpoint(runtime),
|
|
879
|
+
revokeAppRoles: createRevokeAppRolesEndpoint(runtime),
|
|
809
880
|
rockfellerBackchannelLogout: createRockfellerBackchannelLogoutEndpoint(runtime),
|
|
810
881
|
rockfellerWebhooks: createRockfellerWebhooksEndpoint(runtime)
|
|
811
882
|
},
|