Skip to content

Commit

Permalink
feat: update to Expo SDK49 and enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
outaTiME committed Oct 1, 2023
1 parent e637b80 commit e3363da
Show file tree
Hide file tree
Showing 84 changed files with 1,341 additions and 1,281 deletions.
1 change: 0 additions & 1 deletion .easignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ packages/client/ios/build
packages/client/ios/Pods
packages/client/ios/.xcode.env.local
/assets
google-services.json
/sst.json
/stacks
/scriptable-widget.js
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/libs/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const generateScreenshot = async (url, opts) => {
url,
target_url,
duration,
})
}),
);
return {
file: sharp_file,
Expand Down
42 changes: 22 additions & 20 deletions packages/api/src/libs/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const updateFirebaseData = async (uri, payload = {}) =>
}).catch((error) => {
console.warn(
'Unable update firebase with payload',
JSON.stringify({ uri, payload, error: error.message })
JSON.stringify({ uri, payload, error: error.message }),
);
});

Expand Down Expand Up @@ -209,7 +209,7 @@ const getRates = async (base_rates) => {
obj[type] = _.last(rate.stats);
return obj;
},
{}
{},
);
return rates;
};
Expand All @@ -219,7 +219,7 @@ const storeJsonObject = async (
key,
json,
bucket = S3_BUCKET,
is_public = false
is_public = false,
) => {
// try {
// https://blog.jonathandion.com/posts/json-gzip-s3/
Expand Down Expand Up @@ -289,7 +289,7 @@ const storeRateStats = async (rates) => {
obj[type + '_stats'] = new_stats;
return obj;
},
{}
{},
);
return storePublicJsonObject(RATE_STATS_OBJECT_KEY, base_rates);
};
Expand All @@ -306,11 +306,11 @@ const storeHistoricalRatesJsonObject = async (rates) => {
}
// unhandled error
throw error;
}
},
);
Object.entries(rates.rates || {}).forEach(([type, { stats }]) => {
const moment_from = AmbitoDolar.getTimezoneDate(
_.last(stats)[0]
_.last(stats)[0],
).subtract(1, 'year');
const moment_to = AmbitoDolar.getTimezoneDate(_.first(stats)[0]);
// limit base_rates excluding stats
Expand All @@ -322,7 +322,7 @@ const storeHistoricalRatesJsonObject = async (rates) => {
moment_to,
'day',
// moment_to exclusion
'[)'
'[)',
);
return include;
})
Expand All @@ -349,7 +349,7 @@ const storeHistoricalRatesJsonObject = async (rates) => {
obj[type] = rate;
return obj;
},
{}
{},
);
return Promise.all([
storePublicJsonObject(HISTORICAL_RATES_LEGACY_OBJECT_KEY, legacy_rates),
Expand All @@ -361,7 +361,7 @@ const storeHistoricalRatesJsonObject = async (rates) => {
AmbitoDolar.QATAR_TYPE,
// AmbitoDolar.LUXURY_TYPE
// AmbitoDolar.CULTURAL_TYPE
])
]),
),
storePublicJsonObject(HISTORICAL_QUOTES_OBJECT_KEY, base_rates),
]);
Expand All @@ -387,7 +387,7 @@ const storeRatesJsonObject = async (rates, is_updated) => {
obj[type] = rate;
return obj;
},
{}
{},
);
return Promise.all([
is_updated && storeRateStats(rates.rates),
Expand Down Expand Up @@ -437,6 +437,8 @@ const getPathForRate = (type) => {
return 'dolardelujo';
} else if (type === AmbitoDolar.CULTURAL_TYPE) {
return 'dolarcoldplay';
/* } else if (type === AmbitoDolar.CCB_TYPE) {
return 'dolarcripto'; */
}
return `dolar/${type}`;
};
Expand Down Expand Up @@ -477,7 +479,7 @@ const publishMessageToTopic = async (event, payload = {}) => {
JSON.stringify({
event,
payload,
})
}),
);
const params = {
Message: JSON.stringify(payload),
Expand All @@ -501,14 +503,14 @@ const publishMessageToTopic = async (event, payload = {}) => {
id,
event,
duration,
})
}),
);
return id;
})
.catch((error) => {
console.warn(
'Unable to publish message to sns topic',
JSON.stringify({ event, error: error.message })
JSON.stringify({ event, error: error.message }),
);
});
};
Expand Down Expand Up @@ -537,7 +539,7 @@ const triggerEvent = async (event, payload) => {
JSON.stringify({
event,
payload,
})
}),
);
return AmbitoDolar.fetch(
`https://maker.ifttt.com/trigger/${event}/with/key/${process.env.IFTTT_KEY}`,
Expand All @@ -547,7 +549,7 @@ const triggerEvent = async (event, payload) => {
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify(payload),
}
},
)
.then(() => {
const duration = (Date.now() - start_time) / 1000;
Expand All @@ -556,7 +558,7 @@ const triggerEvent = async (event, payload) => {
JSON.stringify({
event,
duration,
})
}),
);
return {
event,
Expand All @@ -567,7 +569,7 @@ const triggerEvent = async (event, payload) => {
// ignore error and trace
console.warn(
'Unable to trigger the event',
JSON.stringify({ event, error: error.message })
JSON.stringify({ event, error: error.message }),
);
});
};
Expand Down Expand Up @@ -628,9 +630,9 @@ const triggerSocials = async (targets, caption, url, file, story_file) => {
JSON.stringify({
target,
error: error.message,
})
}),
);
})
}),
)
.value();
// remove errors
Expand All @@ -656,7 +658,7 @@ const storeImgurFile = async (image) =>

const fetchImage = async (url) =>
AmbitoDolar.fetch(url).then(async (response) =>
Buffer.from(await response.arrayBuffer())
Buffer.from(await response.arrayBuffer()),
);

const wrapHandler = (handler) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/libs/social/instagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export const publish = async (file, caption, story_file) => {
(error) => {
console.warn(
'Unable to get instagram session from bucket',
JSON.stringify({ error: error.message })
JSON.stringify({ error: error.message }),
);
// ignore
}
},
);
const current_session = await loadSession(ig, serialized_session);
if (!current_session) {
Expand Down
12 changes: 6 additions & 6 deletions packages/api/src/libs/social/mastodon.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { login } from 'masto';
import { createRestAPIClient } from 'masto';
import { Blob } from 'node:buffer';

// https://github.com/neet/masto.js/blob/main/examples/create-new-status-with-image.ts
export const publish = async (caption, file) => {
try {
const start_time = Date.now();
const masto = await login({
const masto = await createRestAPIClient({
url: process.env.MASTODON_URL,
accessToken: process.env.MASTODON_ACCESS_TOKEN,
...(process.env.SST_STAGE !== 'prod' && {
Expand All @@ -13,10 +14,9 @@ export const publish = async (caption, file) => {
});
const attachment =
file &&
(await masto.v2.mediaAttachments.create({
// native support of `fetch` on node 18
// file: new Blob([file]),
file,
(await masto.v2.media.create({
file: new Blob([file]),
// file: await fetch(image_url).then((res) => res.blob()),
}));
const { id: status_id } = await masto.v1.statuses.create({
status: caption,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/routes/prune-devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const handler = Shared.wrapHandler(async (event) => {
};
const items = await Shared.getAllDataFromDynamoDB(params);
await Promise.all(
items.map(({ installation_id }) => pruneDevice(installation_id))
items.map(({ installation_id }) => pruneDevice(installation_id)),
);
return Shared.serviceResponse(null, 200, {
items: _.map(items, 'installation_id'),
Expand Down
8 changes: 4 additions & 4 deletions packages/api/src/routes/register-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const handler = Shared.wrapHandler(async (event) => {
JSON.parse(event.body || '{}');
if (!installation_id) {
throw new Error(
'Request query parameter is malformed, missing or has an invalid value'
'Request query parameter is malformed, missing or has an invalid value',
);
}
let update_expression = 'ADD app_loads :val ';
Expand All @@ -34,7 +34,7 @@ export const handler = Shared.wrapHandler(async (event) => {
last_update: timestamp,
},
// push_token is null on initial registration then undefined
_.isNil
_.isNil,
// _.isUndefined
);
if (payload.push_token) {
Expand All @@ -61,7 +61,7 @@ export const handler = Shared.wrapHandler(async (event) => {
ReturnValues: 'ALL_NEW',
};
const { Attributes: data } = await ddbDocClient.send(
new UpdateCommand(params)
new UpdateCommand(params),
);
const { notification_settings: notificationSettings } = data;
const results = {
Expand All @@ -84,7 +84,7 @@ export const handler = Shared.wrapHandler(async (event) => {
console.info(
'Registration or interaction for the device completed',
// JSON.stringify(data)
installation_id
installation_id,
);
return Shared.serviceResponse(null, 200, results);
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/routes/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ export const handler = Shared.wrapHandler(async () => {
try {
const credentials = Buffer.from(
[process.env.AMPLITUDE_API_KEY, process.env.AMPLITUDE_SECRET_KEY].join(
':'
)
':',
),
).toString('base64');
const results = await AmbitoDolar.fetch(
process.env.AMPLITUDE_USAGE_STATS_URL,
{
headers: {
Authorization: `Basic ${credentials}`,
},
}
},
).then(async (response) => {
const { data } = await response.json();
const [users, events, conversions] = _.chain(data?.values)
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/subscribers/funding-notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const handler = Shared.wrapHandler(async (event) => {
JSON.stringify({
generate_only,
targets,
})
}),
);
const screenshot_url = Shared.getSocialScreenshotUrl({
type: 'funding',
Expand All @@ -33,14 +33,14 @@ export const handler = Shared.wrapHandler(async (event) => {
caption,
image_url,
file,
story_file
story_file,
);
console.info('Completed', JSON.stringify(results));
return results;
} catch (error) {
console.warn(
'Unable to generate the screenshot for notification',
JSON.stringify({ error: error.message })
JSON.stringify({ error: error.message }),
);
}
});
26 changes: 13 additions & 13 deletions packages/api/src/subscribers/invalidate-receipts.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ const check = async (items = [], readonly) => {
'Receipts',
JSON.stringify({
amount: receiptIds.length,
})
}),
);
const receiptIdChunks = expo.chunkPushNotificationReceiptIds(receiptIds);
// leave only the records with errors
const invalid_receipts = await Promise.all(
receiptIdChunks.map((chunk) =>
expo.getPushNotificationReceiptsAsync(chunk)
)
expo.getPushNotificationReceiptsAsync(chunk),
),
)
// merge objects inside array
.then((receiptChunks) => Object.assign({}, ...receiptChunks.flat()))
Expand All @@ -57,23 +57,23 @@ const check = async (items = [], readonly) => {
}
return obj;
},
[]
)
[],
),
)
.catch((error) => {
console.error(
'Unable to get receipts',
JSON.stringify({
error: error.message,
})
}),
);
throw error;
});
if (!readonly) {
await Promise.all(
invalid_receipts.map(({ installation_id }) =>
invalidateDevice(installation_id)
)
invalidateDevice(installation_id),
),
);
}
return {
Expand All @@ -95,7 +95,7 @@ export const handler = Shared.wrapHandler(async (event) => {
JSON.stringify({
date_from,
readonly,
})
}),
);
const filter_expression = '#notification_date >= :date_from';
const expression_attribute_values = {
Expand All @@ -121,12 +121,12 @@ export const handler = Shared.wrapHandler(async (event) => {
Shared.getTickets(date, type).catch((error) => {
console.warn(
'Unable to get notification tickets from bucket',
JSON.stringify({ date, type, error: error.message })
JSON.stringify({ date, type, error: error.message }),
);
})
)
}),
),
).then((data) =>
_.chain(data).flatten().compact().uniqBy('installation_id').value()
_.chain(data).flatten().compact().uniqBy('installation_id').value(),
);
const results = await check(tickets, readonly === true);
console.info('Completed', JSON.stringify(results));
Expand Down
Loading

0 comments on commit e3363da

Please sign in to comment.