Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

[misc] Hook organics #1305

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions reference/organics/flow/build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# `build`

Build a value by running some logic, then using the return value.

### Usage

| | Argument | Type | Details |
|---|:--------------------|-------------------|:-----------------------------------|
| 1 | builder | ((ref)) | The function to be run in order to build the result. Note that this function should not cause any side effects.


##### Result

| Type | Description |
|:--------------------|:-----------------|
| ((ref)) | The value returned by the builder function
16 changes: 16 additions & 0 deletions reference/organics/flow/dive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# `Dive`

Dive into some recursive logic, inputted as a function.

### Usage

| | Argument | Type | Details |
|---|:--------------------|-------------------|:-----------------------------------|
| 1 | recursee | ((ref)) | The recursive logic function to run
| 2 | maxDepth | ((number)) | (Optional) A maximum depth (zero-indexed)

##### Result

| Type | Description |
|:--------------------|:-----------------|
| ((ref)) | The (optional) result from performing this recursive dive
1 change: 1 addition & 0 deletions reference/organics/flow/flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
These helpers are used as utilities for asynchronous flow control.
11 changes: 11 additions & 0 deletions reference/organics/flow/for-each.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `forEach`

Run a given function once for each item in an array or a dictionary.

### Usage

| | Argument | Type | Details |
|---|:--------------------|-------------------|:-----------------------------------|
| 1 | arrayOrDictionary | ((ref)) | The array or dictionary over which to loop
| 2 | iteratee | ((ref)) | The function to run for each item in the object

14 changes: 14 additions & 0 deletions reference/organics/flow/iterate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# `iterate`

Run a given function every time the given wellspring says to run it.
Note on ‘splash’: A splash is the moment in time when the wellspring invokes the given function, eachSplash.

### Usage

| | Argument | Type | Details |
|---|:--------------------|-------------------|:-----------------------------------|
| 1 | wellspring | ((ref)) | The function that triggers a sequence of splashes, saying when, how many times, and with what value to run the given eachSplash function.
| 2 | eachSplash | ((ref)) | The function to run each time the wellspring splashes out a value.
| 3 | eachBatch | ((ref)) | The function to run when the current batch of values fills up and if the wellspring finishes without filling up the last batch
| 4 | skipDuplicates | ((boolean)) | Whether or not to skip running eachSplash if the splashed value has been seen before. Uses a strict equality check (===).
| 5 | batchSize | ((number)) | The number of un-skipped times the wellspring can splash before considering the batch full and invoking eachBatch with an array of the values of the batch.
7 changes: 7 additions & 0 deletions reference/organics/flow/pause.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# `pause`

Wait for at least the given number of milliseconds before proceeding.

| | Argument | Type | Details |
|---|:--------------------|-------------------|:-----------------------------------|
| 1 | ms | ((number)) | The number of milliseconds to wait (must be greater than or equal to 0)
16 changes: 16 additions & 0 deletions reference/organics/flow/simultaneously-for-each.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# `simultaneouslyForEach`

Run a given function once for each item in an array or a dictionary.

### Usage

| | Argument | Type | Details |
|---|:--------------------|-------------------|:-----------------------------------|
| 1 | arrayOrDictionary | ((ref)) | The array or dictionary over which to loop
| 2 | iteratee | ((ref)) | The function to run for each item in the object

##### Result

| Type | Description |
|:--------------------|:-----------------|
| ((ref)) | An array or dictionary of the results, which is the combined result of running iteratee on each item/property
15 changes: 15 additions & 0 deletions reference/organics/flow/simultaneously.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# `simultaneously`

Run multiple functions at the same time, then assembles the return values into the structure defined by stencil.

### Usage

| | Argument | Type | Details |
|---|:--------------------|-------------------|:-----------------------------------|
| 1 | stencil | ((ref)) | The one-dimensional array or dictionary, consisting of functions to run in parallel.

##### Result

| Type | Description |
|:--------------------|:-----------------|
| ((ref)) | An array or dictionary of the return values of the functions run in parallel.
10 changes: 10 additions & 0 deletions reference/organics/flow/until.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# `until`

Run a given function repeatedly until its return value is `true`.

### Usage

| | Argument | Type | Details |
|---|:--------------------|-------------------|:-----------------------------------|
| 1 | checker | ((ref)) | The function to be run until it returns `true`
| 2 | timeout | ((number)) | (optional) A timeout value, in milliseconds
19 changes: 19 additions & 0 deletions reference/organics/gravatar/get-avatar-url.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# `getAvatarUrl`

Determine the source URL for the gravatar image belonging to a particular email address

### Usage

| | Argument | Type | Details |
|---|:--------------------|-------------------|:-----------------------------------|
| 1 | emailAddress | ((string)) | The email address associated with the desired avatar image.
| 2 | gravatarSize | ((number)) | The desired height and width of the avatar image in pixels (between 1 and 2048).
| 3 | defaultImage | ((string)) | The backup image to use in case this email address has no matching avatar.
| 4 | rating | ((string)) | The most extreme rating level to consider "appropriate" for your audience ("G", "PG", "R", or "X".)
| 5 | useHttps | ((boolean)) | Whether to build a secure avatar URL ("https://".)

##### Result

| Type | Description |
|:--------------------|:-----------------|
| ((string)) | Avatar source URL
1 change: 1 addition & 0 deletions reference/organics/gravatar/gravatar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This helper is used to look up the avatar image associated with a particular email address.
5 changes: 5 additions & 0 deletions reference/organics/organics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# sails-hook-organics

`sails-hooks-organics` exposes a set of commonly used functions as helpers. These helpers represent functions hand-chosen by the Sails core team for their usefulness in building Sails- and Node-based applications.

<docmeta name="displayName" value="Organics">
10 changes: 10 additions & 0 deletions reference/organics/passwords/check-password.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# `checkPassword`

Check a password attempt by comparing an inputted password with the existing bcrypt hash of the correct password.

### Usage

| | Argument | Type | Details |
|---|:--------------------|-------------------|:-----------------------------------|
| 1 | passwordAttempt | ((string)) | The new password attempt (unencrypted)
| 2 | hashedPassword | ((string)) | The existing password hash against which to compare the attempt
16 changes: 16 additions & 0 deletions reference/organics/passwords/hash-password.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# `hashPassword`

Hash an inputted password using the one-way bcrypt hashing algorithm.

### Usage

| | Argument | Type | Details |
|---|:--------------------|-------------------|:-----------------------------------|
| 1 | password | ((string)) | The password to hash
| 2 | strength | ((number)) | The number of iterations it takes to generate the cryptographic key.

##### Result

| Type | Description |
|:--------------------|:-----------------|
| ((string)) | The password hash generated by running the provided password through the bcrypt hashing algorithm.
1 change: 1 addition & 0 deletions reference/organics/passwords/passwords.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
These helpers may be used for password encryption and authentication.
23 changes: 23 additions & 0 deletions reference/organics/sendgrid/send-html-email.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# `sendHtmlEmail`

Send an automated HTML email using the SendGrid API.

### Usage

| | Argument | Type | Details |
|---|:--------------------|-------------------|:-----------------------------------|
| 1 | to | ((string)) | The email address of the desired recipient
| 2 | subject | ((string)) | The subject line of the email
| 3 | htmlMessage | ((string)) | The HTML body of the email
| 4 | from | ((string)) | The email address of the sender
| 5 | fromName | ((string)) | The display name of the sender, to be displayed in the recipient inbox
| 6 | secret | ((string)) | The secret API key from a valid SendGrid developer account
| 7 | toName | ((string)) | The full name of the primary recipient
| 8 | bcc | ((string)) | The list of email addresses of recipients secretly copied on the email
| 9 | attachments | ((string)) | The attachments to include on the email, with file content encoded as base64

##### Result

| Type | Description |
|:--------------------|:-----------------|
| ((string)) | A SendGrid message ID; does not guarantee successful delivery.
1 change: 1 addition & 0 deletions reference/organics/sendgrid/sendgrid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
These helpers are for communicating with the SendGrid API, which is used to send automated emails.
20 changes: 20 additions & 0 deletions reference/organics/stripe/charge-customer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# `chargeCustomer`

Create and capture a charge for a specified amount using the saved default payment source of a Stripe customer.

### Usage

| | Argument | Type | Details |
|---|:--------------------|-------------------|:-----------------------------------|
| 1 | stripeCustomerId | ((string)) | The ID of the Stripe customer to charge
| 2 | amount | ((number)) | The amount of currency to charge, expressed in the smallest currency unit. Must be greater than or equal to $0.50 US or equivalent in charge currency.
| 3 | chargeDescription | ((string)) | The text to include in automatic email receipts (if in use) and to display in the Stripe web interface alongside this charge.
| 4 | statementDescriptor | ((string)) | The text to be displayed on the customer’s credit card statement
| 5 | currency | ((string)) | The three-letter ISO currency code in lowercase indicating the currency used in this transaction.
| 6 | secret | ((string)) | The secret API key

##### Result

| Type | Description |
|:--------------------|:-----------------|
| ((string)) | The ID of the processed Stripe charge
19 changes: 19 additions & 0 deletions reference/organics/stripe/save-billing-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# `saveBillingInfo`

Save the latest billing details in Stripe for a new or existing customer

### Usage

| | Argument | Type | Details |
|---|:--------------------|-------------------|:-----------------------------------|
| 1 | stripeCustomerId | ((string)) | The ID of the Stripe customer whose information should be updated. If unspecified, this creates a new customer entry in Stripe.
| 2 | token | ((string)) | The token used to create the source
| 3 | emailAddress | ((string)) | The email address of the Stripe customer
| 4 | plan | ((string)) | The unique identifier for the plan object
| 5 | secret | ((string)) | The secret API key.

##### Result

| Type | Description |
|:--------------------|:-----------------|
| ((string)) | The ID of the Stripe customer updated or created.
1 change: 1 addition & 0 deletions reference/organics/stripe/stripe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
These helpers are used to communicate with the Stripe API to charge credit cards, etc.