π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: cover more errors
Nevo David6784a283d0a0
diff --git a/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts b/libraries/nestjs-libraries/src/integrations/social/facebook.provider.tsindex f8815be61..08d1bdff7 100644--- a/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts@@ -69,13 +69,6 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {};}- if (body.indexOf('490') > -1) {- return {- type: 'refresh-token' as const,- value: 'Access token expired, please re-authenticate',- };- }-if (body.indexOf('REVOKED_ACCESS_TOKEN') > -1) {return {type: 'refresh-token' as const,@@ -128,6 +121,13 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {};}+ if (body.indexOf('1366051') > -1) {+ return {+ type: 'bad-body' as const,+ value: 'These photos were already posted.',+ };+ }+if (body.indexOf('1609008') > -1) {return {type: 'bad-body' as const,@@ -180,6 +180,26 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {};}+ if (body.indexOf('4854002') > -1) {+ return {+ type: 'bad-body' as const,+ value:+ 'Confirm your identity before you can publish as this Page. Open the Facebook app on your phone and follow the instructions',+ };+ }+ if (body.indexOf('(#100) No permission to publish the video') > -1) {+ return {+ type: 'bad-body' as const,+ value: 'Facebook return: No permission to publish the video',+ };+ }+ if (body.indexOf('490') > -1) {+ return {+ type: 'refresh-token' as const,+ value: 'Access token expired, please re-authenticate',+ };+ }+if (status === 401) {return {type: 'bad-body' as const,@@ -770,4 +790,3 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {}}}-diff --git a/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts b/libraries/nestjs-libraries/src/integrations/social/instagram.provider.tsindex 560697d69..d0f3e4ac6 100644--- a/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts@@ -51,6 +51,9 @@ export class InstagramProviderif (!firstPost?.length) {return 'Should have at least one media';}+ if (firstPost.length > 10) {+ return 'Instagram carousel only supports up to 10 media attachments';+ }if (settings?.is_trial_reel) {if ((firstPost?.length ?? 0) > 1) {return 'Trial Reels can only have one video';@@ -99,7 +102,10 @@ export class InstagramProvider};}- if (body.indexOf('REVOKED_ACCESS_TOKEN') > -1 || body.indexOf('"error_subcode":33') > -1) {+ if (+ body.indexOf('REVOKED_ACCESS_TOKEN') > -1 ||+ body.indexOf('"error_subcode":33') > -1+ ) {return {type: 'refresh-token' as const,value:@@ -120,7 +126,8 @@ export class InstagramProviderif (body.toLowerCase().indexOf('session has been invalidated') > -1) {return {type: 'refresh-token' as const,- value: 'You session has been invalidated, this can usually happen from frequent posting, please re-authenticate, and wait 1-2 days before posting again',+ value:+ 'You session has been invalidated, this can usually happen from frequent posting, please re-authenticate, and wait 1-2 days before posting again',};}@@ -327,6 +334,20 @@ export class InstagramProvider};}+ if (body.indexOf('2207077') > -1) {+ return {+ type: 'bad-body' as const,+ value: 'Instagram Video download failed',+ };+ }++ if (body.indexOf('too little or too many attachments') > -1) {+ return {+ type: 'bad-body' as const,+ value: 'Instagram carousel should have between 2 and 10 media attachments',+ }+ }+if (body.indexOf('2207027') > -1) {return {type: 'bad-body' as const,@@ -619,7 +640,9 @@ export class InstagramProviderwhile (status === 'IN_PROGRESS') {const { status_code } = await (await this.fetch(- `https://${type}/v20.0/${photoId}?access_token=${userToken || accessToken}&fields=status_code`,+ `https://${type}/v20.0/${photoId}?access_token=${+ userToken || accessToken+ }&fields=status_code`,undefined,'',0,@@ -652,7 +675,9 @@ export class InstagramProviderconst { permalink } = await (await this.fetch(- `https://${type}/v20.0/${mediaId}?fields=permalink&access_token=${userToken || accessToken}`+ `https://${type}/v20.0/${mediaId}?fields=permalink&access_token=${+ userToken || accessToken+ }`)).json();lastPermalink = permalink;@@ -678,7 +703,9 @@ export class InstagramProviderconst { permalink } = await (await this.fetch(- `https://${type}/v20.0/${mediaId}?fields=permalink&access_token=${userToken || accessToken}`+ `https://${type}/v20.0/${mediaId}?fields=permalink&access_token=${+ userToken || accessToken+ }`)).json();@@ -708,7 +735,9 @@ export class InstagramProviderwhile (status === 'IN_PROGRESS') {const { status_code } = await (await this.fetch(- `https://${type}/v20.0/${containerId}?fields=status_code&access_token=${userToken || accessToken}`,+ `https://${type}/v20.0/${containerId}?fields=status_code&access_token=${+ userToken || accessToken+ }`,undefined,'',0,@@ -730,7 +759,9 @@ export class InstagramProviderconst { permalink } = await (await this.fetch(- `https://${type}/v20.0/${mediaId}?fields=permalink&access_token=${userToken || accessToken}`+ `https://${type}/v20.0/${mediaId}?fields=permalink&access_token=${+ userToken || accessToken+ }`)).json();@@ -771,7 +802,9 @@ export class InstagramProvider// Get the permalink from the parent postconst { permalink } = await (await this.fetch(- `https://${type}/v20.0/${postId}?fields=permalink&access_token=${userToken || accessToken}`+ `https://${type}/v20.0/${postId}?fields=permalink&access_token=${+ userToken || accessToken+ }`)).json();diff --git a/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts b/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.tsindex 5fff90ede..050178452 100644--- a/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts@@ -85,7 +85,7 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {};}- if (body.indexOf('resource is forbidden') > -1) {+ if (body.indexOf('resource is forbidden') > -1 || body.indexOf('Service Unavailable') > -1) {return {type: 'retry',value: 'Resource is forbidden',@@ -314,8 +314,35 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {const finalOutput = video || image || document;const etags = [];- for (let i = 0; i < picture.length; i += 1024 * 1024 * 2) {- const upload = await this.fetch(+ if (isVideo) {+ // Only the Videos API uses multipart chunked uploads. Each 2MB part is+ // PUT separately and the returned etags are passed to finalizeUpload.+ for (let i = 0; i < picture.length; i += 1024 * 1024 * 2) {+ const upload = await this.fetch(+ sendUrlRequest,+ {+ method: 'PUT',+ headers: {+ 'X-Restli-Protocol-Version': '2.0.0',+ 'LinkedIn-Version': '202601',+ Authorization: `Bearer ${accessToken}`,+ 'Content-Type': 'application/octet-stream',+ },+ body: picture.slice(i, i + 1024 * 1024 * 2),+ },+ 'linkedin',+ 0,+ true+ );++ etags.push(upload.headers.get('etag'));+ }+ } else {+ // Images and documents (PDF carousels) use a single-shot upload URL and+ // must be sent as one PUT of the whole file. Chunking here would send+ // multiple overwriting PUTs to the same URL, leaving LinkedIn with only+ // the final chunk and corrupting anything larger than 2MB.+ await this.fetch(sendUrlRequest,{method: 'PUT',@@ -323,20 +350,14 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {'X-Restli-Protocol-Version': '2.0.0','LinkedIn-Version': '202601',Authorization: `Bearer ${accessToken}`,- ...(isVideo- ? { 'Content-Type': 'application/octet-stream' }- : isPdf- ? { 'Content-Type': 'application/pdf' }- : {}),+ ...(isPdf ? { 'Content-Type': 'application/pdf' } : {}),},- body: picture.slice(i, i + 1024 * 1024 * 2),+ body: picture,},'linkedin',0,true);-- etags.push(upload.headers.get('etag'));}if (isVideo) {@@ -364,7 +385,20 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {// wait until it reaches the AVAILABLE status before attaching it to a// post, otherwise LinkedIn rejects the post with a processing error.await this.waitForMediaToBeReady(video, accessToken, 'videos');- } else if (!isPdf) {+ } else if (isPdf) {+ // Documents (PDF carousels) are processed asynchronously too and must be+ // AVAILABLE before being attached to a post, otherwise LinkedIn rejects+ // the post or publishes a broken carousel.+ if (type === 'company') {+ // Organization-owned documents can be polled for their status.+ await this.waitForMediaToBeReady(document, accessToken, 'documents');+ } else {+ // A w_member_social (personal) token is write-only for rest/documents+ // and can't perform the GET, so polling would always be forbidden.+ // Give LinkedIn a moment to finish processing before attaching it.+ await timer(10000);+ }+ } else {// Images are also processed asynchronously and must be AVAILABLE before// being attached to a post.if (type === 'company') {@@ -389,11 +423,12 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {private async waitForMediaToBeReady(urn: string,accessToken: string,- type: 'videos' | 'images',+ type: 'videos' | 'images' | 'documents',maxAttempts = 20,intervalMs = 30000): Promise<void> {- const label = type === 'videos' ? 'video' : 'image';+ const label =+ type === 'videos' ? 'video' : type === 'documents' ? 'document' : 'image';for (let attempt = 0; attempt < maxAttempts; attempt += 1) {const json = await (diff --git a/libraries/nestjs-libraries/src/integrations/social/x.provider.ts b/libraries/nestjs-libraries/src/integrations/social/x.provider.tsindex b64269e10..ae703015f 100644--- a/libraries/nestjs-libraries/src/integrations/social/x.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/x.provider.ts@@ -90,12 +90,27 @@ export class XProvider extends SocialAbstract implements SocialProvider {};}+ if (body.includes('You are not allowed to create a Tweet')) {+ return {+ type: 'bad-body',+ value: 'You are not allowed to create a post with duplicate content',+ }+ }+if (body.includes('usage-capped')) {return {type: 'bad-body',value: 'Posting failed - capped reached. Please try again later',};}++ if (body.includes('user-suspended')) {+ return {+ type: 'bad-body',+ value:+ 'Your X account has been suspended, please reconnect with another account',+ };+ }if (body.includes('duplicate-rules')) {return {type: 'bad-body',