feat(medusa): PublishableAPI keys model (#2543)
This commit is contained in:
@@ -52,6 +52,8 @@ export * from "./product-tax-rate"
|
||||
export * from "./product-type"
|
||||
export * from "./product-type-tax-rate"
|
||||
export * from "./product-variant"
|
||||
export * from "./publishable-api-key"
|
||||
export * from "./publishable-api-key-sales-channel"
|
||||
export * from "./refund"
|
||||
export * from "./region"
|
||||
export * from "./return"
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { PrimaryColumn } from "typeorm"
|
||||
|
||||
import { FeatureFlagEntity } from "../utils/feature-flag-decorators"
|
||||
import PublishableAPIKeysFeatureFlag from "../loaders/feature-flags/publishable-api-keys"
|
||||
|
||||
@FeatureFlagEntity(PublishableAPIKeysFeatureFlag.key)
|
||||
export class PublishableApiKeySalesChannel {
|
||||
@PrimaryColumn()
|
||||
sales_channel_id: string
|
||||
|
||||
@PrimaryColumn()
|
||||
publishable_key_id: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @schema publishable_api_key_sales_channel
|
||||
* title: "Publishable API key sales channel"
|
||||
* description: "Holds mapping between Publishable API keys and Sales Channels"
|
||||
* x-resourceId: publishable_api_key_sales_channel
|
||||
* properties:
|
||||
* sales_channel_id:
|
||||
* type: string
|
||||
* description: The sales channel's ID
|
||||
* example: sc_01G1G5V21KADXNGH29BJMAJ4B4
|
||||
* publishable_key_id:
|
||||
* type: string
|
||||
* description: The publishable API key's ID
|
||||
* example: pak_01G1G5V21KADXNGH29BJMAJ4B4
|
||||
*/
|
||||
@@ -0,0 +1,62 @@
|
||||
import { BeforeInsert, Column } from "typeorm"
|
||||
|
||||
import { BaseEntity } from "../interfaces"
|
||||
import { resolveDbType } from "../utils/db-aware-column"
|
||||
import { generateEntityId } from "../utils"
|
||||
import { FeatureFlagEntity } from "../utils/feature-flag-decorators"
|
||||
import PublishableAPIKeysFeatureFlag from "../loaders/feature-flags/publishable-api-keys"
|
||||
|
||||
@FeatureFlagEntity(PublishableAPIKeysFeatureFlag.key)
|
||||
export class PublishableApiKey extends BaseEntity {
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
created_by: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
revoked_by: string | null
|
||||
|
||||
@Column({ type: resolveDbType("timestamptz"), nullable: true })
|
||||
revoked_at?: Date
|
||||
|
||||
@BeforeInsert()
|
||||
private beforeInsert(): void {
|
||||
this.id = generateEntityId(this.id, "pubkey")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @schema publishable_api_key
|
||||
* title: "Publishable API key"
|
||||
* description: "Publishable API key defines scopes (i.e. resources) that are available within a request."
|
||||
* x-resourceId: publishable_api_key
|
||||
* properties:
|
||||
* id:
|
||||
* type: string
|
||||
* description: The key's ID
|
||||
* example: pak_01G1G5V27GYX4QXNARRQCW1N8T
|
||||
* created_by:
|
||||
* type: string
|
||||
* description: "The unique identifier of the user that created the key."
|
||||
* example: usr_01G1G5V26F5TB3GPAPNJ8X1S3V
|
||||
* created_by_user:
|
||||
* description: A user object. Available if the relation `created_by_user` is expanded.
|
||||
* type: object
|
||||
* created_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was created."
|
||||
* format: date-time
|
||||
* revoked_by:
|
||||
* type: string
|
||||
* description: "The unique identifier of the user that revoked the key."
|
||||
* example: usr_01G1G5V26F5TB3GPAPNJ8X1S3V
|
||||
* revoked_by_user:
|
||||
* description: A user object. Available if the relation `revoked_by_user` is expanded.
|
||||
* type: object
|
||||
* revoked_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the key was revoked."
|
||||
* format: date-time
|
||||
* updated_at:
|
||||
* type: string
|
||||
* description: "The date with timezone at which the resource was updated."
|
||||
* format: date-time
|
||||
*/
|
||||
Reference in New Issue
Block a user