Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@planet-a/affinity-node

Package Overview
Dependencies
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@planet-a/affinity-node - npm Package Compare versions

Comparing version 0.0.1-test.7 to 0.0.1-test.8

3

esm/v1/field_value_changes.js

@@ -57,2 +57,5 @@ import { fieldValueChangesUrl } from './urls.js';

}
/**
* TODO(@joscha): transform DateTime values to Date objects and then change type {@link ValueRaw} to {@link Value}
*/
static transformFieldValueChange(fieldValueChange) {

@@ -59,0 +62,0 @@ return {

40

esm/v1/field_values.js

@@ -29,32 +29,8 @@ import { fieldValuesUrl } from './urls.js';

}
static isValidISO8601(dateString) {
// Define the regular expression for ISO 8601 format
const iso8601Regex = /^(-?(?:[1-9][0-9]*)?[0-9]{4})(-(0[1-9]|1[0-2])(-([0-2][0-9]|3[01])(T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(\.\d+)?(Z|([+-]([01][0-9]|2[0-3]):[0-5][0-9])))?)?)?$/;
// Check if the string matches the ISO 8601 format
if (!iso8601Regex.test(dateString)) {
return false;
}
// Parse the date using the Date object
const date = new Date(dateString);
return date.toISOString() === dateString;
}
static transformValue(value) {
if (value instanceof Date) {
return value.toISOString();
}
else if (typeof value === 'string' && FieldValues.isValidISO8601(value)) {
// TODO(@joscha): introspection of the value shape is not ideal, as it will transform a text value that happens
// to be a valid ISO date string into a Date object. This is a limitation of the current design.
// A way around this can be to fetch the field definition and use that to determine the value type.
// The attached cost is an additional API request for each field value in string shape, which is not ideal.
return new Date(value);
}
else {
return value;
}
}
static transformFieldValue(fieldValue) {
return {
...fieldValue,
value: FieldValues.transformValue(fieldValue.value),
value: fieldValue.value_type === FieldValueType.DATE
? new Date(fieldValue.value)
: fieldValue.value,
updated_at: fieldValue.updated_at === null

@@ -108,3 +84,5 @@ ? null

...data,
value: FieldValues.transformValue(data.value),
value: data.value instanceof Date
? data.value.toISOString()
: data.value,
}, {

@@ -136,3 +114,7 @@ transformResponse: [

async update(data) {
const response = await this.axios.put(fieldValuesUrl(data.field_value_id), { value: FieldValues.transformValue(data.value) }, {
const response = await this.axios.put(fieldValuesUrl(data.field_value_id), {
value: data.value instanceof Date
? data.value.toISOString()
: data.value,
}, {
transformResponse: [

@@ -139,0 +121,0 @@ ...defaultTransformers(),

{
"name": "@planet-a/affinity-node",
"version": "0.0.1-test.7",
"version": "0.0.1-test.8",
"description": "API wrapper for the affinity.co API",

@@ -5,0 +5,0 @@ "keywords": [

import type { AxiosInstance } from 'axios';
import type { Person } from './list_entries.js';
import type { DateTime } from './types.js';
import type { ValueRaw } from './field_values.js';
/**

@@ -27,3 +28,3 @@ * Via https://stackoverflow.com/questions/40510611

}
export type Changer = {
export type Changer = Person & {
/**

@@ -33,22 +34,2 @@ * The unique identifier of the changer.

id: number;
} & Person;
export type Value = {
/**
* The unique identifier of the value.
*/
id: number;
/**
* Represents the field's value.
*/
text: string;
/**
* The rank of the value.
*
* TODO(@joscha): can this be null for some value types?
*/
rank: number;
/**
* The color associated with the value.
*/
color: number;
};

@@ -95,3 +76,3 @@ /**

*/
value: Value;
value: ValueRaw;
};

@@ -165,2 +146,5 @@ export type FieldValueChangeResponseRaw = FieldValueChangeRaw[];

constructor(axios: AxiosInstance);
/**
* TODO(@joscha): transform DateTime values to Date objects and then change type {@link ValueRaw} to {@link Value}
*/
private static transformFieldValueChange;

@@ -167,0 +151,0 @@ /**

import type { AxiosInstance } from 'axios';
import { FieldValueType } from './lists.js';
import type { DateTime } from './types.js';
import { FieldBase } from './fields.js';
export type { DateTime } from './types.js';
export type DropdownValue = string;
export type DropdownValue = {
/**
* The unique identifier of the value.
*/
id: number;
/**
* Represents the field's value.
*/
text: string;
/**
* The color associated with the value.
*/
color: number;
};
export type RankedDropdownValue = DropdownValue & {
/**
* The rank of the value.
*/
rank: number;
};
export type NumberValue = number;

@@ -16,6 +36,6 @@ export type PersonValue = number;

export type TextValue = string;
export type ValueRaw = DropdownValue | NumberValue | PersonValue | OrganizationValue | LocationValue | DateTime | TextValue;
export type ValueRaw = DropdownValue | RankedDropdownValue | NumberValue | PersonValue | OrganizationValue | LocationValue | DateTime | TextValue;
export type Value = Omit<ValueRaw, DateTime> | Date;
export interface FieldValueRawValues extends Record<keyof FieldValueType, ValueRaw> {
[FieldValueType.RANKED_DROPDOWN]: DropdownValue;
[FieldValueType.RANKED_DROPDOWN]: RankedDropdownValue;
[FieldValueType.DROPDOWN]: DropdownValue;

@@ -29,2 +49,37 @@ [FieldValueType.NUMBER]: NumberValue;

}
export interface FieldValueValues extends Record<keyof FieldValueType, Value> {
[FieldValueType.RANKED_DROPDOWN]: RankedDropdownValue;
[FieldValueType.DROPDOWN]: DropdownValue;
[FieldValueType.NUMBER]: NumberValue;
[FieldValueType.PERSON]: PersonValue;
[FieldValueType.ORGANIZATION]: OrganizationValue;
[FieldValueType.LOCATION]: LocationValue;
[FieldValueType.DATE]: Date;
[FieldValueType.TEXT]: TextValue;
}
type ValueTypeMixin<T extends (FieldValueRawValues | FieldValueValues)> = {
value_type: FieldValueType.DROPDOWN;
value: T[FieldValueType.DROPDOWN];
} | {
value_type: FieldValueType.RANKED_DROPDOWN;
value: T[FieldValueType.RANKED_DROPDOWN];
} | {
value_type: FieldValueType.NUMBER;
value: T[FieldValueType.NUMBER];
} | {
value_type: FieldValueType.PERSON;
value: T[FieldValueType.PERSON];
} | {
value_type: FieldValueType.ORGANIZATION;
value: T[FieldValueType.ORGANIZATION];
} | {
value_type: FieldValueType.LOCATION;
value: T[FieldValueType.LOCATION];
} | {
value_type: FieldValueType.DATE;
value: T[FieldValueType.DATE];
} | {
value_type: FieldValueType.TEXT;
value: T[FieldValueType.TEXT];
};
/**

@@ -42,3 +97,3 @@ * Each field value object has a unique id.

*/
export type FieldValueRaw = {
export type FieldValueRaw = FieldBase & {
/**

@@ -57,10 +112,7 @@ * The unique identifier of the field value object.

/**
* The unique identifier of the list entry object the field value is associated with. This only exists if the field the value is associated with is list-specific.
* The unique identifier of the list entry object the field value is associated with.
* This only exists if the field the value is associated with is list-specific, `null` marks a global field value.
*/
list_entry_id: number | null;
/**
* The value attribute can take on many different types, depending on the field {@link Field.value_type}.
*/
value: ValueRaw;
/**
* The string representing the time when the field value was created.

@@ -73,9 +125,8 @@ */

updated_at: DateTime | null;
};
} & ValueTypeMixin<FieldValueRawValues>;
export type FieldValueResponseRaw = FieldValueRaw[];
export type FieldValue = Omit<FieldValueRaw, 'value' | 'updated_at' | 'created_at'> & {
value: Value;
updated_at: Date | null;
created_at: Date;
};
} & ValueTypeMixin<FieldValueValues>;
export type FieldValueResponse = FieldValue[];

@@ -124,4 +175,2 @@ export type CreateFieldValueRequest = {

constructor(axios: AxiosInstance);
private static isValidISO8601;
private static transformValue;
private static transformFieldValue;

@@ -128,0 +177,0 @@ /**

import type { AxiosInstance } from 'axios';
import { EntityType, Field, FieldValueType } from './lists.js';
export type FieldResponse = Field[];
export type FieldsQueryParameters = {
export type FieldBase = {
/**
* An unique identifier of the list whose fields are to be retrieved.
*
* Pass the `list_id` to only fetch fields that are specific to that list. Otherwise, all global and list-specific fields will be returned.
*/
list_id?: number;
/**
* The value type of the fields that are to be retrieved.

@@ -16,3 +10,3 @@ *

*/
value_type?: FieldValueType;
value_type: FieldValueType;
/**

@@ -23,4 +17,12 @@ * The entity type of the fields that are to be retrieved.

*/
entity_type?: EntityType;
entity_type: EntityType;
};
export type FieldsQueryParameters = Partial<FieldBase> & {
/**
* An unique identifier of the list whose fields are to be retrieved.
*
* Pass the `list_id` to only fetch fields that are specific to that list. Otherwise, all global and list-specific fields will be returned.
*/
list_id?: number;
/**
* When `true`, field names will return in the format `[List Name] Field Name`.

@@ -38,3 +40,3 @@ *

};
export type FieldCreateParameters = {
export type FieldCreateParameters = FieldBase & {
/**

@@ -41,0 +43,0 @@ * The name of the field.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc